How to add/remove the trailing slashes in URLs using the .htaccess? – Knowledgebase


How to add/remove the trailing slashes in URLs using the .htaccess?

You can use the below code in the .htaccess file depending on the trailing slash required or not –

No trailing slash

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [R=301,L]

Trailing slash

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R]

Also Read

Powered by WHMCompleteSolution

Leave a Comment

Your email address will not be published. Required fields are marked *

Open chat