Remove trailing slash in url (Apache)

In my site, it was redirecting urls with a trailing slash (/)

domain.com/file.html -> domain.com/file.html/

I have added following code to remove trailing slash .htaccess

DirectorySlash Off

# internally add the slash back
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ /$1/ [L]

Now I have working domain.com/file.html - without trail slash. Enjoy!

  • Roopz © 2020