Grammatically correct 301 redirect

Discussion in 'Apache' started by David3, Apr 9, 2010.

  1. #1
    For an .htaccess 301 redirect from a non-WWW to a WWW, which is "more correct?" Both seem to work just fine and do what I want, but I know each code-symbol does something important, so in the long run, which is better, please?

    This one?

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^example\.com
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]

    ...or this one?

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^example\.com
    rewriterule ^(.*)$ http://www.example.com/$1 [R=301,L]

    Thank you. :)
     
    David3, Apr 9, 2010 IP
  2. JREAM

    JREAM Member

    Messages:
    160
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #2
    The the ladder,

    ^(.*) -- This will match better just incase anything were to be funky.

    Cheers,
    Jesse
     
    JREAM, Apr 10, 2010 IP
  3. mplx

    mplx Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    jream, what's the pratical difference between (.*) and ^(.*) or how can this be abused?
    AFAIK any character (.) repeated zero or more times (*) will always matches a string from the beginning (^) so both should be the same as well as ^(.*)$ or (.*)$
     
    mplx, Apr 11, 2010 IP
  4. David3

    David3 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    @Jream, thank you for your reply.... BUT your reply says ^(.*)
    Did you leave off the $ on purpose? I want to make sure I do it correctly. Which is better: ^(.*) or this: ^(.*)$

    I'm also curious about mpix's (the previous poster) question.

    Anyway, looks like there are 3 choices:
    a.) (.*)
    b.) ^(.*)
    c.) ^(.*)?
     
    David3, Apr 11, 2010 IP
  5. David3

    David3 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Well, I'm still not sure what's best. I realize my question was probably answered somewhere in this thread, but there is still some ambiguity appearing to me. I'd appreciate anyone's comments on this.:)
     
    David3, Apr 17, 2010 IP