Reputation: 747
I need to redirect all URLs ending in "/" to urls that don't end in "/".
Example:
domain.com/ -> domain.com
domain.com/page1/ -> domain.com/page1
domain.com/category1/ -> domain.com/category1
domain.com/// -> domain.com
I've tried the following approaches, but none work:
RewriteRule ^(.*)\/+$ http:\/\/www\.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule (.*)\/+$ http:\/\/www\.%{HTTP_HOST}/$1 [R=301,L]
Upvotes: 1
Views: 1314
Reputation: 785058
You can use this rule in root .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1 [NE,R=302,L]
RewriteCond %{THE_REQUEST} \s/{2,}[?\s]
RewriteRule ^$ / [R=302,L]
Upvotes: 1