Chofoteddy
Chofoteddy

Reputation: 747

Redirect all urls ending in "/"

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:

Upvotes: 1

Views: 1314

Answers (1)

anubhava
anubhava

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

Related Questions