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

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....

How to configure Amazon S3 backups in WHM?

There is always issues on the server like Hard Drive Failures and its very important to keep your...

Install PHP-SSH2 extension in cPanel

PHP SSH2 extension to be loaded into the cPanel server as this module is not available inside...

Response: 530 Login authentication failed Error: Critical error: Could not connect to server.

I was unable to connect to FTP using correct credentials with the below error message - Status:...

Powered by WHMCompleteSolution