Apache: Remove trailing slash (redirect to remove trailing slash) in .htaccess
If you want to redirect from http://example.com/test/ to http://example.com/test (i.e. remove the slash at the end of URLs) then you can use the following .htaccess code:
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteRule ^(.*)/$ /$1 [R=301,L]
This will 301 redirect to the non trailing slash version of the page
Don't forget that you will probably need to enable the rewrite engine for these rules to work. Click the button below to find out how to do this.
More...
Comments and discussion about Remove trailing slash (redirect to remove trailing slash) in .htaccess
Found this interesting? Maybe you want to read some more in this series?
Or see other topics in the Apache language
Rewrite and Redirection .htaccess Rules
.htaccess Security
General .htaccess Tricks
General Apache Tips
Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScriptOr see random questions
How does PHP compare objects?
How to change the order that migrations happen?
How to block IPv6 IP addresses in .htaccess
How to check if a string contains a certain substring?
How to get a route to directly show a view?
How to manually write your own pagination in PHP
What is WordPress default Apache .htaccess rules?
How to block multiple IP addresses in .htaccess
How to increment a value in the database
How to namespace a Laravel route group?