Removing Trailing Slash with .htaccess

435 Views Asked by At

I am trying yo remove the trail slash from an url with this pattern

http://localhost/~francesco/mycms/about/

to make it

http://localhost/~francesco/mycms/about

I have tried lots of rules but no one is working for me.

My rewrite rule is this by now

Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~francesco/mycms/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ index.php?page=$1 [L]
</IfModule>

Hope someone can help me!

1

There are 1 best solutions below

3
On

Try placing this rule

RewriteRule ^(about)/$ $1 [L,R=301,NC]

just after

RewriteBase /~francesco/mycms/

If you want to work for any first level directory following the RewriteBase i.e. http://localhost/~francesco/mycms/[anything-here]/ use

#exclude the /~francesco/mycms/admin/directory
RewriteCond %{REQUEST_URI} !^/admin/ [NC] 
RewriteRule ^([^/]+)/$ $1 [L,R=301,NC]