Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Mod Rewrite and trailing slashes

    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.

  • #2
    Regular Coder
    Join Date
    Feb 2009
    Location
    Wheeling, IL
    Posts
    358
    Thanks
    5
    Thanked 62 Times in 60 Posts
    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:

    Code:
    # 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.
    The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.

    How to ask smart questions?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •