Reputation: 10581
I would like to remove the last '/' from all urls using a 301 .htaccess redirect. How would I do it? I have tried the following, but it only removes from the first level of directories:
RewriteCond %{REQUEST_URI} ^(/[^/]+)/$
RewriteRule . http://www.mysite.net%1 [L,R=301]
For example, it works for www.mysite.net/first/ but does not work for www.mysite.net/first/second/
Upvotes: 1
Views: 297
Reputation: 143876
Change the [^/]+
to just .+
. The ^/
means "match everything except for a slash", so "first" matches but "first/second" doesn't. Also, you don't need a condition here.
RewriteRule ^(.*)/$ http://www.mysite.net/$1 [L,R=301]
Upvotes: 1