1

I would like to add trailing slash for deep level of my urls

So let's say i have this url

mysite.com/work

when user access that url, i want to be redirected to:

mysite.com/work/ (this i want to happen)

But i want this only deep levels, not for .html pages

mysite.com/testing.html/ (i don't want this to happen)

I have this .htaccess rule, but this add trailing slash to my .html pages also. i don't want that.

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [L,R=301]

Any help?

unor
  • 92,415
  • 26
  • 211
  • 360
PHPCore
  • 121
  • 9

1 Answers1

0

You can use this rule for adding trailing slash only for non-files:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{THE_REQUEST} \s/+(.*?)[^/][?\s]
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301,NE]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • It's still adding trailing slash to my html files. e.g test.html/ i want only for paths or folders – PHPCore Oct 19 '14 at 17:44