Revo Burisan Revo Burisan - 4 months ago 19
Apache Configuration Question

Double slash and end slash on file

I am using

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

this code helps to remove double slashes. But now I have another problem that I cant solve about an hour..

How can I remove the end slash if its a "file"? <-- good <-- bad

is it possible to write all those codes in one line or more professional? I am still learning.

Thank you!


Right below the RewriteEngine On line, add:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

to enforce a no-trailing-slash policy.

To enforce a trailing-slash policy:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]