Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess rewrite condition trailing slash only for specific directories

I have this rule which works great and adds a trailing slash for every directory on my site. How Can I add trailing slashes for only certain directories such /courses/ ? I don't want every directory / path to have a trailing slash.

  RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
  RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
like image 401
Brian Barthold Avatar asked Jan 20 '23 17:01

Brian Barthold


1 Answers

RewriteCond %{REQUEST_URI} ^/(courses|foo|bar)$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]

Should work where courses, foo and bar are directories that you want to add a trailing slash to.

like image 108
James C Avatar answered Jan 28 '23 12:01

James C