skip to Main Content

To remove multiple slashes I wrote this condition that is working in windows system but not in Ubuntu 18.04 I don’t know why..?

RewriteCond %{HTTP_HOST} !=""
RewriteCond %{THE_REQUEST} ^[A-Z]+s//+(.*)sHTTP/[0-9.]+$
RewriteRule .* %{HTTP_HOST}/%1 [R=301,L]

I am getting this error in ubuntu system..

Forbidden
You don’t have permission to access this resource.

And my URL changed this

http://in.decashop.localhost/p/8489882_500-boys-gym-short-sleeved-t-shirt-grey.html

to this

http://in.decashop.localhost/var/www/html/decashopglobal/www/in.decashop.localhost/p/8489882_500-boys-gym-short-sleeved-t-shirt-grey.html

if I put multiple slashes like

http://in.decashop.localhost///p/8489882_500-boys-gym-short-sleeved-t-shirt-grey.html

3

Answers


  1. Chosen as BEST ANSWER

    This Rule worked for me..

    RewriteBase /
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}s/+(.*?)/+(/[^s]+) [NC]
    RewriteRule ^ %1%2 [R=302,L,NE]
    

    Thanks To All.


  2. At first, you can check apache’s log. try to access your website using URL or IP and check your Webserver’s log information.

    In ubuntu you can try:

    sudo tail -f /var/log/apache2/error.log

    In most cases wrong permission is the main cause of this problem.

    Login or Signup to reply.
  3. RewriteCond %{HTTP_HOST} !=""
    RewriteCond %{THE_REQUEST} ^[A-Z]+s//+(.*)sHTTP/[0-9.]+$
    RewriteRule .* %{HTTP_HOST}/%1 [R=301,L]
    

    The output you are seeing is consistent with the directives you have posted, as you are missing the scheme (ie. http) on the substitution string in the RewriteRule directive (which presumably should be an absolute URL) – so I don’t see how this would have “worked” on the Windows server? Unless you had a very different config (but even then it couldn’t have worked the same way).

    With the RewriteRule directive as written, the substitution string (ie. %{HTTP_HOST}/%1) would be seen as a relative URL and Apache would then add back the directory-prefix ie. /var/www/html/decashopglobal/www/ prior to issueing the redirect – which naturally results in the malformed redirect you are seeing. If you had set a RewriteBase directive elsewhere in the config file, then this would have overridden this behaviour (although still wouldn’t have produced the output you seem to be expecting).

    Also note that these directives are intended to remove multiple slashes from the start of the URL-path only, not elsewhere in the URL-path.

    So, you would need to change the RewriteRule directive to read:

    RewriteRule ^ http://%{HTTP_HOST}/%1 [R=301,L]
    

    OR, remove the HTTP_HOST server variable altogether (to make the substitution string root-relative):

    RewriteRule ^ /%1 [R=301,L]
    

    You will need to clear your browser cache before testing, as the erroneosu 301 (permanent) redirects will be cached persistently by the browser. (Test with 302s to avoid caching issues in the future.)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search