Removing trailing slashes with mod rewrite?
This relates to my previous question (which can be viewed here ). I would like to be able to remove the trailing slash from the url so that it doesn't mess up certain areas of my site. Htaccess code is here:
# -s = File Exists
RewriteCond %{REQUEST_FILENAME} -s [OR]
# -l = Is a SymLink
RewriteCond %{REQUEST_FILENAME} -l [OR]
# -d = Is a Directory
RewriteCond %{REQUEST_FILENAME} -d
# if we match any of the above conditions - serve the file.
RewriteRule ^.*$ - [NC,L]
# only allows '.' in the "page" portion.
RewriteRule ^([^/.]+)/?$ index.php?section=$1 [L]
RewriteRule ^([^/.]+)/([^/]+)/?$ index.php?section=$1&page=$2 [L]
RewriteRule ^([^/.]+)/([^/]+)/([^/.]+)/?$ index.php?section=$1&page=$2&split=$3 [L]
As before, I'm not in my depth with this, so can anyone help?
+2
source to share
1 answer
I assume you are talking about the rule:
RewriteRule ^.*$ - [NC,L]
While others are already dropping the trailing slash.
Try this instead:
RewriteRule ^(.*)/$ $1 [NC,L]
This is what I see in the logs (abbreviated):
applying pattern '^(.*)/$' to uri 'host/'
rewrite 'host/' -> 'host'
So I'm fine.
+5
source to share