Print

Printed September 9, 2010 from B&T's Tips & Scripts
http://tips-scripts.com


Fixing the trailing slash problem

If you have a pointed domain or subdomain, and you wish to load the default page for a subdirectory under the pointed directory, and you do not have a trailing slash on the address, you get the pointed directory name inserted in the URL.   Use this htaccess code to fix that problem

RewriteRule ^([^\.]+[^/])$ http://%{HTTP_HOST}/$1/ [R=301,L]

The way this works is if the request does not have a slash at the end and does not contain a period then it will be rewritten with a slash at the end.   So you cannot use this method if your directory names contain periods or if you use search arguments in the defualt loading page without specifying the page name (with a period in it).

Be sure and put these two lines above the other redirects in the .htaccess file, but after the RewriteEngine On statement.