1

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.

http://www.test.com/var/www/html/test/public/admin

halfer
  • 19,824
  • 17
  • 99
  • 186
Hiren Shah
  • 225
  • 1
  • 10

1 Answers1

0

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]
Community
  • 1
  • 1
Hiren Shah
  • 225
  • 1
  • 10