Forum Moderators: phranque

Message Too Old, No Replies

Proper way to 301 a site

www.mysite.com to mysite.com

         

twist

8:17 am on Mar 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I just read this thread,

[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?

1milehgh80210

8:28 am on Mar 10, 2005 (gmt 0)

10+ Year Member



I just used this solution (in .htaccess)
__________________________
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain\.com
RewriteRule ^(.*)$ [yourdomain.com...] [R=permanent,L]
____________________________
seems to work..(hope its okay, I'm no expert)
ps. tried using cpanel redirect (permanent) which did'nt work at all. The redirect worked using firefox, but not I.E.?

diddlydazz

3:03 pm on Mar 10, 2005 (gmt 0)

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



hi 1milehgh80210

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

pmkpmk

3:40 pm on Mar 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's a third way to do it :-) :

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]

twist

3:52 pm on Mar 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks everybody, I'll try 1milehgh80210's way of doing it for now and thanks pmkpmk for alternatives.

As for using 301 vs permanent, any difference?

jdMorgan

7:01 pm on Mar 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



301/permanent: No difference.

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

twist

7:05 pm on Mar 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Wow, thanks jdMorgan for clearing that up. I always wondered about the www thing.

sitz

1:29 am on Mar 11, 2005 (gmt 0)

10+ Year Member



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.1

www IN CNAME example.com.


All fine and good, but if a datacenter loses power/net, 33.33+% of your users will get HTTP timeouts when trying to reach your site. Less than ideal. =)

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.

The switch is then configured with the IPs of each of the 3 VIPs, and given a fairly low TTL (on the order of 5 minutes). Any DNS request made for www.example.com points the client to www.gslb.example.com, and the switch returns an IP for one of the configured VIPs, generally in a round-robin fashion. To monitor for errors, the gslb switch performs L4 health checks on each of the configured VIPs; if it detects a VIP is unreachable or otherwise down, it simply doesn't return the IP address for that VIP. Presto, instance recovery!

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).

nex99

1:02 pm on Mar 15, 2005 (gmt 0)

10+ Year Member



Can i follow the 301 redirect rule for redirect a sub-domain to another sub-domain with different url. like: abc.1stdomain.com to abc.4thdomain.com

what should i use for this kind of redirection... .htaccess or cpanel redirect?