I am working on an .htaccess rule.
I want to remove trailing slash form all url.
For ex:-
http://www.test.com/admin Working fine
But
http://www.test.com/admin/ Gives me error.
If I run URL like http://www.test.com/admin/dashboard/ then its auomatically redirect to http://www.test.com/admin/dashboard
I have put below code in htaccess file.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [L,R=301]
But its redirect like this.
Origianl answer - Htaccess: add/remove trailing slash from URL
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]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.