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]
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to Re-arrange accounts in WHM?

Please go through the following steps on How to Re-arrange accounts in WHM 1. Go to WHM and...

How to limit email recipients on exim to 10 email addresses?

You might come under a situation where your client expects you to secure their mail server and...

Fatal error: Call to undefined function utf8_substr()

While accessing Opencart site, I was getting error as 'Fatal error: Call to undefined function...

Unable to perform operation. No free disk space.

I'm getting this error when I tried to send an email from webmail:Unable to perform operation....

Failed: Account Restore Failed: “clean: Cannot cleanup top level directory:

While restoring the full cPanel backup file in 'tar.gz' format from WHM >> Backup >>...

Powered by WHMCompleteSolution