| DNS vs .htaccess - what's the ideal way to configure? A question about best practice in setting up domains |
Trav

msg:4298587 | 10:32 pm on Apr 15, 2011 (gmt 0) | Hi All, First, I apologize; it's likely this question has been asked a few times before, but I can't really figure out how to best search it. The question is: what's the best practice for setting up your zone file and .htaccess to redirect URL's to a canonical URL? Currently I have my Zone like so: www.example.com CNAME IN 86400 example.com example.com A IN 86400 000.000.000.000 And then in my .htaccess I've got: RewriteCond %{HTTP_HOST} ^example.com$ RewriteRule ^(.*)$ "http://www.example.com/$1" [R=301,L] While this is working, it got me to thinking: Am I making a loop here? Seems like i'm essentially telling a visiting browser: 1. Go to www.example.com 2. www.example.com is actually example.com 3. example.com points to www.example.com So, thought I'd post here and see what the consensus is.
|
Trav

msg:4300029 | 7:32 pm on Apr 18, 2011 (gmt 0) | Hmm, not quite the flood of responses I was hoping for : ) Well, if anyone should see this and even has a link to some reading which can clarify this for me, I'd be mighty appreciative. Feel free to post it via a private message if it's not appropriate for the board. Trav
|
g1smd

msg:4300041 | 7:59 pm on Apr 18, 2011 (gmt 0) | Posting this in the Apache sub-forum would have brought a near-instantaneous response. :) Point all domains at your server, then add this code in the root:
DirectoryIndex index.php index.html # RewriteEngine On # RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$ RewriteRule (.*) http://www.example.com/$1 [R=301,L]
|
Trav

msg:4300047 | 8:13 pm on Apr 18, 2011 (gmt 0) | Thanks g1smd, wasn't sure if it verged more on the domain side or the Apache side. If I may, I have a couple of follow-ups on your response. When you say 'point all domains at your server', would this more verbosely be "make the A record for each domain point at the IP of your server"? I ask, because I'm trying to understand the importance of CNAME's here. Second, in that .htaccess, would that not make it so that ANY domain pointed at the IP would be redirected to the WWW, and if so, does that imply any sort of security risk? I.E. a competitor points the domain www.spammy-widgets.com at my IP, and because of the .htaccess it resolves to my homepage with a 301.
|
|
|