Forum Moderators: phranque
[webmasterworld.com...]
and, after reading a suggestion in one of the posts, am wondering what is the proper and best way to redirect www.mysite.com to mysite.com or vice versa.
First off, what is better and why, www or no www, whats the difference? Just a link to a good thread on the issue will be sufficient since I imagine this must have been discussed plenty already.
As for creating the 301 redirect I have seen at least 2 explanations so far,
<VirtualHost example.com www.example.com>
Redirect / [example.com...]
CustomLog logs/redir "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
</VirtualHost>
Then just the,
Redirect 301 ht*p://www.example.com/ ht*p://example.com/
If the address I am going to use isn't indexed yet, should I just use the second one?
thats the same code as i used (appears to be fairly standard), seems to be working fine
i checked using [searchengineworld.com...]
perhaps some more experienced htaccess members (especially jdMorgan) might be able confirm/clarify or tell us otherwise ;o)
Dazz
RedirectTemp / [company.com...]
RedirectPermanent / [company.com<...]Oh, and if you want to redirect ANYTHING which comes to your default server to a single base URL, then use this:
RewriteEngine on
RewriteCond %{HTTP_HOST}!^www\.mysite\.com
RewriteRule (.*) http://www.mysite.com$1 [R=301,L]
Whether you use "www" or not in your URL doesn't matter much either. Look at it from a marketing viewpoint; If you are a well-known brand, you probably don't need the www. If you're not, then the "www" can serve as an eye-catcher in print media and TV, an ear-catcher in broadcast media, and it emphasizes that you have a Web presence.
Technically, it makes no difference whether you use a domain or the www subdomain of that domain, as long as you are utterly consistent. To avoid problems, this should be decided before putting a site on-line, and the redirect should be in place when the site goes live. This way, you will minimize the number of links to the "wrong" domain name.
A warning: Do not use a 302 redirect unles you really mean that the page is moved only temporarily. To find out why, do a search for "302 Hijacking" here on WebmasterWorld.
Jim
First off, what is better and why, www or no www, whats the difference?
In certain situations, the presence/absence of the 'www' can make a huge difference. Take a situation where you have a site powered by 15 machines, divided into 3 VIPs of 5 machines each, and each VIP is, say, in a different datacenter. With 3 VIPs, you have a couple of options; you set up a static A record rotor in DNS like this:
example.com. IN A 192.168.1.1
IN A 192.168.10.1
IN A 192.168.20.1www IN CNAME example.com.
Obviously, one could remove the bad IP from DNS, but then one needs to wait for DNS to propogate, and wouldn't be be nice to have something a bit more automated?
A few switch vendors have implemented 'global server load balancing'; in this scenerio, one CNAMEs the DNS names for the site to a DNS zone controlled by the switch:
www.example.com IN CNAME www.gslb.example.com.
Except. In this example, the domain is 'example.com', and 'www' is a hostname in that zone. While you can have the name of the domain itself (called the 'origin') point to an IP (or more than one IP), you cannot CNAME it; it's illegal, and won't work. The solution? Configured 'example.com' as a static A record rotor (as shown at the top of this now-rather-lengthy post) and redirect all requests for 'example.com' to 'www.example.com', which is protected by the gslb system. Not complete protection, but *better* protection than the alternative. Obviously, under this system, you want to minimize the number of links to 'example.com' in favor of 'www.example.com'.
Or, just don't use 'example.com' at all. =)
(note: if anyone knows of a trick to work around this, I'm all eyes. I don't claim to be the final authority on /anything/, but I've not been able to find another way to handle this situation thus far).