Paolo Sanna
Paolo Sanna

Reputation: 73

MOD_REWRITE - URL ENDING TRAILING SLASH

Options -Indexes +FollowSymLinks -MultiViews
RewriteEngine On

RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteCond %{HTTP_HOST} !^(.*)\.(.*)\. [NC] 
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ HTTP%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_URI} !(/$|\.) 
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L] 

ServerSignature Off

RewriteRule ^cookie-policy/?$ cookie_policy.php [NC,L]`

Hello I'm struggling really hard with URL closing trailing slash.

RewriteRule ^cookie-policy/?$ cookie_policy.php [NC,L]

I would like, for example, to force a redirection from www.website.com/cookie-policy to www.website.com/cookie-policy/

Upvotes: 0

Views: 395

Answers (1)

Joe
Joe

Reputation: 4907

Use this:

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

It will add a / to end of your URLs. Make sure you clear your cache before testing this.

Upvotes: 1

Related Questions