lisovaccaro
lisovaccaro

Reputation: 33956

.htacess redirect to remove '/' at the end of URL?

For some reason some links create slashes at the end of urls. I discovered the same link in a different device can or cannot add a slash at the end of the URL.

Due to my htaccess structuring I sometimes get errors if the URLs have slashes. Is there a way to remove them from URLs with htaccess?

EG:

example.com/s/

instantly redirects to:

example.com/s

Upvotes: 0

Views: 827

Answers (2)

anasaitali
anasaitali

Reputation: 1514

This do the job and you don't need to specify the domain :

RewriteRule ^(.+)/$ /$1 [R=301,L]

Upvotes: 0

lobianco
lobianco

Reputation: 6276

A similar question gave this answer:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} (.*)$
RewriteRule ^(.+)/$ http://www.domain.com/$1 [R=301,L]

Upvotes: 1

Related Questions