Trailing Slash for the Root Directory

Discussion in 'Apache' started by AHA7, Mar 24, 2009.

  1. #1
    Hello,

    Is there a way to redirect "http://example.com" to "http://example.com/" using .htaccess?

    The request URL for both of them is /. Is there a way to force the trailing slash for the root directory of my site?
     
    AHA7, Mar 24, 2009 IP
  2. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #2
    as far as I know that would be default behavior of an apache - to internally redirect to / if slash is missing on a folder.
    since this redirect is additional work for apache it normally is better to have links to your site already with a url with trailing /

    otherwise I am usure why you want .htaccess do what apache does by default
     
    hans, Mar 30, 2009 IP
  3. Lpe04

    Lpe04 Peon

    Messages:
    579
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #3
    RewriteRule ^$ http://www.mydomain.com/ [R=301,L]
    Code (markup):
     
    Lpe04, Mar 31, 2009 IP
  4. AHA7

    AHA7 Peon

    Messages:
    445
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I don't think that will work, because the request URI would be / (^/$) in both cases.
     
    AHA7, Mar 31, 2009 IP
  5. Lpe04

    Lpe04 Peon

    Messages:
    579
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ^$ would be nothing. ^/$ would be one slash. Correct?
     
    Lpe04, Apr 1, 2009 IP
  6. AHA7

    AHA7 Peon

    Messages:
    445
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The user must make the following request in both cases:

    GET [B]/[/B] HTTP/1.1
    Host: www.mydomain.com
    Code (markup):
     
    AHA7, Apr 1, 2009 IP