Forum Moderators: phranque

Message Too Old, No Replies

Avoiding a 301 Loop and other problems

Moving to a new domain

         

artefaqs

2:04 pm on Jun 15, 2009 (gmt 0)

10+ Year Member



I am moving one of my web sites to a new domain.

The site is currently mapped to /usr/name/unified/ on my server.

From what I've read on the internet, the easiest way to do this and preserve my Google rankings is to add this line to my .htaccess:

redirect 301 / http://www.example.com/

This will send traffic destined for the original domain to the new domain, which is also mapped to /usr/name/unified

BUT if I do this, will the redirected traffic also see the 301 redirect when it arrives, and then redirect again, or is Apache smart enough to know what domain it's already on and not send people into a loop?

ALSO --

I have several other web sites that are also mapped to /usr/name/unified/ and the scripts in that directory tailor the output for those sites based on the URL (each is geographically unique).

If I do the simple 301 described above, it will direct ALL traffic for ALL domains that point to /usr/name/unified/ to the brand new domain and make a mess of things, won't it?

jdMorgan

7:20 pm on Jun 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> BUT if I do this, will the redirected traffic also see the 301 redirect when it arrives, and then redirect again, or is Apache smart enough to know what domain it's already on and not send people into a loop?

If all domains are co-hosted in the same directory, then your Redirect directive will be applied to all requests, and yes, you will have a loop.

You need a better tool that can check the requested hostname in addition to just the URL-path, so use mod_rewrite instead of mod_alias:


Options +FollowSymLinks -MultiViews
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^([^.]+\.)*old-domain\.tld [NC]
RewriteRule ^(.*)$ http://new-domain.com/$1 [R=301,L]

This redirects old-domain.tld, www.old-domain.tld, and all other subdomains of old-domain.tld to new-domain.com, retaining the originally-requested URL-paths and query strings. No other domains or their subdomains will be redirected.

See the resources cited in our Forum Charter for more information.

Jim

[edited by: jdMorgan at 7:34 pm (utc) on June 17, 2009]

artefaqs

2:24 pm on Jun 17, 2009 (gmt 0)

10+ Year Member



Thanks for the advice. I actually ended up going another route.

I adjusted a variable in the original directory to detect the new domain instead of the old domain.

Then I mapped the old domain to a directory with nothing but .htaccess file in it containing the 301.

Then I mapped the new domain to the original directory.

Everything works!

Your method appears more elegant, compact, and "right." But I ended up going with my solution simply for the reason that I understand it. I don't like to put stuff on the server that I don't understand enough to fix if it breaks. Regular expressions are one such nightmare. I've been fortunate enough to be able to avoid them thus far in the pages that I code, and anything that isn't my work I have a paid support contract on.

Thanks again!

jdMorgan

3:00 pm on Jun 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's very wise not to use methods you don't understand. I actually warn about this in many of my posts here, since using mod_rewrite is most definitely not a "copy and paste" proposition.

However, note that without a redirect, it will take search engines a longer time to completely re-index your site, and the PageRank and link-popularity of inbound links to the old URLs will be lost. Also, an investment of time and effort into learning regular expressions will undoubtedly pay off in the long run, as it is used in almost all modern scripting languages and is a very powerful and useful tool.

Jim

artefaqs

3:12 pm on Jun 17, 2009 (gmt 0)

10+ Year Member



I've tried wrapping my brain around regexp a few times, but every time I think I understand it, my tests prove otherwise.

As for the redirect, there is a 301 redirect in the new/dummy directory that the old web site has been mapped to. In my browser it works fine, and looks OK in the Live Headers extension of Firefox.

I have read elsewhere that there will be a penalty for a while until Google gets all the links updated. But do you think the method I've chosen is more problematic than an ordinary site move?

jdMorgan

4:57 pm on Jun 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Almost all "penalties" are imaginary -- and the result of either ignorance or a guilty conscience.

There is no potential penalty here, just a delay. While Google returns results in thousandths of a second, re-building and re-ranking their index can take weeks. But penalties are simply more "fascinating" and they preserve the "SEO mystique," and so the concept survives.

For example, we talk a lot about "duplicate-content penalties" here -- problems that can arise if any given content is directly-accessible from more than one URL -- like example.com/ and www.example.com/, for example. This is not a penalty, but rather two URLs both getting indexed and ranked separately, and therefore competing with each other for PageRank and eyeballs. While the major search engines do their best to "figure it out" for us, this is a back-end process, and so prone to delays and errors. It is much better to simply detect all non-canonical URL requests and redirect them to the one canonical URL, presenting the search engines with a tidy URL-space that doesn't need any clean-up at all.

Now, if you go and intentionally create several dozen copies of the same content at different URLs, then you might garner a "you are wasting our bandwidth, disk, and CPU resources" penalty from Google. But they generally assume incompetence before they assume trickery. Consider, for example, that many sites will return the same page for any of these (and many more):

example.com/
example.com./
example.com:80/
example.com.:80/
www.example.com/
www.example.com./
www.example.com:80/
www.example.com.:80/
example.com/?<anything whatsoever here>

So, there are at least eight --and with the query string, many, many more-- URIs that will all return the same content... But the Webmaster didn't do this intentionally at all. Rather, he/she failed to prevent it.

If you've got a proper 301 redirect in place, and everything looks good in Live HTTP Headers, then you're good to go.

Jim

g1smd

6:36 pm on Jun 17, 2009 (gmt 0)

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



Make sure that you get from 'non-canonical URL request' to 'final canonical URL' in just one hop... avoid a redirection chain for any and all requests.

That's also easy to check using Live HTTP Headers.

artefaqs

7:22 pm on Jun 17, 2009 (gmt 0)

10+ Year Member



Jim,

Thanks for that long response. It's about the most rational, logical thing I've ever read on the internet about search engines. Most of what I've read over the years has been along the lines of hysteria as various charlatans try to read Google's tea leaves.

It's interesting that you bring up the whole example.com vs. www.example.com thing. My hosting company automatically treats them the same. I wonder if over the years that has diluted my pagerank in some way. The site I'm working with is a 5, but used to be a 6/7 a couple of years ago.

The redirect I'm using should cover me:

redirect 301 / [newexamplesite.com...]

Since my hosting company shoves both www and non-www prefixed addresses into that .htaccess file, all requests should be 301ed into the www version of the new domain. Maybe combining all of that traffic in that way will help concentrate my rating.

Or maybe it's all tea leaves again. Who knows? I'll just stick to the policy I've had since I started this -- Content. Content. Content.

jdMorgan

7:47 pm on Jun 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Content, content, content, and use HTML <Head> tags and HTML markup for their intended purpose.

Nobody says you can't have a strong <title>, a compelling <meta description>, use HTML tags like <H1>, <H2> etc., use HTML tag attributes for their intended purposes, use meaningful link-text in prominently-placed and important links, and build a rational information-linking structure into the site. Three-quarters of the benefit of SEO can be gained by correcting mistakes and improving poorly-implemented elements of the site. All of the other SEO stuff nets little benefit compared to just "doing it right on the pages" and having something truly useful to offer to readers of those pages. (Of course, it also helps if your readers are prolific linkers as well...) ;)

This from someone with hats of many shades on my rack... although I prefer the lighter tones.

Jim

g1smd

9:09 pm on Jun 17, 2009 (gmt 0)

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



"If you're already using RewriteRule on your site, do not mix directives using Redirect or Redirectmatch in with those; use only RewriteRule for all Redirects and for all Rewrites" is also a warning I see Jim posting on an almost weekly basis here.