Forum Moderators: phranque

Message Too Old, No Replies

.htaccess

Which is the correct format?

         

textex

10:21 pm on May 15, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is one of the below better than the other?

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

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

[edited by: incrediBILL at 1:58 am (utc) on May 16, 2012]
[edit reason] fixed URLS, use Example.com [/edit]

lucy24

12:45 am on May 16, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That sound you hear in the distance is Our Bill shedding big tears because he went to a lot of trouble composing that post about always using example.com, especially when it comes out as http://example.com ...

Flags have no order, so there is no difference between [R=301,L] and [L,R=301]. But if you're trying to form good habits, it would make sense to always put L as the last flag in a list.

Both rules have problems more serious than the presence or absence of +FollowSymLinks. They won't make your server explode, they just won't do 100% of what you want them to do.

textex

12:53 am on May 16, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What sort of problems can result? And how can I fix?

g1smd

11:06 pm on May 16, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Escape literal periods in patterns.

You rule won't redirect non-canonical requests such as www.example.com:80/ and so on.

You'll need
!^(www\.example\.com)?$
as your pattern.

This question has been asked and answered several times so far this month. Check recent threads.