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]

Was this answer helpful?

 Print this Article

Also Read

An --**warning**-- occurred while installing profile “--**warning**--: failed to create directory /home/cPanel_username/.cagefs”.

While updating Easy Apache 3 to Easy Apache 4 on CloudLinux server using below command - cd...

Account Creation Status: failed Each username’s first 8 characters must be unique.

While creating the cPanel account on WHM, below error was generated - Account Creation Status:...

How to backup single MySQL table?

Backup single MySQL table using shell command and phpMyAdmin 1. Creating dump file -...

404 Page not found

While accessing the website I was getting the error as '404 Page not found' with below server...

FATAL: Failed to download updatenow.static from server: The system cannot update the /var/cpanel/sysinfo.config file. at /usr/local/cpanel/Cpanel/GenSysInfo.pm line 115 : upcp failed

You may come across the message "***** FATAL: Failed to download updatenow.static from server:...

Powered by WHMCompleteSolution