Deepak Ranjan Jena
Deepak Ranjan Jena

Reputation: 437

how to redirect a webpage ending with "/" using .htaccess

I have a website and i am using .htaccess to generate SEO friendly url. I want if someone type: mysitename.com/anypagename he should be redirected to mysitename.com/anypagename/

The basic is i want to concat a "/" at the end. Can anyone tell me the how to write this in my .htaccess file

Upvotes: 0

Views: 189

Answers (1)

anubhava
anubhava

Reputation: 785058

Try following rule in your .htaccess file:

RewriteEngine on
Options +FollowSymlinks -MultiViews
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /$1/ [L,R=301,NE,QSA]

R=301 will redirect with https status 301
L will make last rule
NE is for no escaping query string
QSA will append your existing query parameters

$1 is your REQUEST_URI

PS: If you want to avoid appending a / after a regular file then add this condition as well above:

RewriteCond %{REQUEST_FILENAME} !-f

Upvotes: 2

Related Questions