...

View Full Version : Mod Rewrite and trailing slashes



FastCougar
08-19-2010, 04:23 AM
I need to create a rewrite rule to that if a user types in a URL like so:

www.mydomain.com/
or
www.mydomain.com

it redirects to
www.mydomain.com/index.htm

Conversely, this same rule needs to apply to all subdirectories so that

www.mydomain.com/subdir
and
www.mydomain.com/subdir/

redirects to

www.mydomain.com/subdir/index.htm

The reason for this is that we are using a CDN that caches the URL as 3 different URLs

www.mydomain.com/subdir
is different from
www.mydomain.com/subdir/
is different from
www.mydomain.com/subdir/index.htm

We want everything to redirect to /index.htm regardless of how they type it.

Eldarrion
08-19-2010, 03:39 PM
That sounds more like a DirectoryIndex issue than anything else as a correctly set up DirectoryIndex directive should look for index.htm, regardless of trailing slash or not. Still, if you are looking for a rewrite, you'll need to have at least one rule for each sub-level of your directories.

Kind of like this:



# First subdir level rewrite
RewriteRule ^(\w+)/?$ /$1/index.htm [L]
# Main dir level rewrite
RewriteRule ^/?$ /index.htm [L]


Enjoy, though I still think you'd have better luck looking into the DirectoryIndex directive.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum