Forum Moderators: phranque
I ask, because for some strange reason, www.domain.tld/folder - does not work, yet www.domain.tld/folder/ will work. There is a possibility that there could be numerous folders to go through.
Is this best covered by using .htaccess, or is there something else I could try?
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_URI}!(.*)/$
RewriteRule ^(.*)$ [domain.com...] [L,R=301]
If there is a better solution, please let me know - thanks!
On Apache, mod_dir [httpd.apache.org] generally does a fix-up on missing trailing slashes for directories, if no such page exists. In other words, if the page "/folder" does not exist, mod_dir will append a slash and check if it exists as a directory. If so, then it redirects to that URL.
If for some reason you cannot get mod_dir installed or working, the same thing can be done with mod_rewrite, although mod_dir is much more efficient:
# If requested filename does not exist as a file
RewriteCond %{REQUEST_FILENAME} !-f
# but does exist as a directory when a slash is appended
RewriteCond %{REQUEST_FILENAME}/ -d
# then redirect any URL-path without a slash or "." in the final path-part, appending a slash
RewriteRule ^(([^/]+/)*[^/.]+)$ http://www.example.com/$1/ [R=301,L]
Jim
[edited by: jdMorgan at 12:02 am (utc) on Feb. 22, 2007]