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


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]

Leave a Comment

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

Open chat