Forum Moderators: Robert Charlton & goodroi

Message Too Old, No Replies

Best practices for 301 redirect from domain1 to domain2

         

realmaverick

4:04 pm on Sep 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Afternoon guys,

I'm 301 redirecting an established domain to another for rebranding purposes. We're doing this to gain a more brand-able name.

A concern is obviously Google. We have 30,000 visitors a day, so a lot to lose if this goes wrong.

I've acquired an already established, related domain. One issue is the website was established under subdomain.sitename.com rather than www.

The obvious answer would be to 301 to www. But then the URL's will conflict with the URLs of the website that it's being 301 redirected to.

Would it make sense at this point to 301 to www.sitename.com/subfolder and have a single link in the navigation, that leads back to www.sitename.com as well as limit link juice routes in an attempt to filter as much of the link juice to the live website at /

Any advice would be appreciated. I'm a little unsure what to do with this one.

Thanks.

tedster

9:28 pm on Sep 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Would it make sense at this point to 301 to www.sitename.com/subfolder and have a single link in the navigation, that leads back to www.sitename.com

I'm not following this very well. How does that avoid the url conflict?

zehrila

12:38 am on Sep 25, 2009 (gmt 0)

10+ Year Member



I didn't understand it well, from what i have guessed, i feel it would not end up very well. A frined 301 his established site to another domain and he ended up loosing all his traffic, if it's not broken, don't fix it.

jd01

12:56 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah, I was going to reply last night, but couldn't figure out how redirecting to a new URL could possibly cause a conflict with a URL and I didn't feel like waiting for a reply.

If it's done correctly they hit the old URL and land on the new one... Not sure how it matters from one site or two and there's a workaround for about everything, including determining the originally requested URL, so I'm at a loss on this one.

realmaverick

6:33 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry for my poor explanation in my opening post.

I have a successful website with almost 2 million members and a few hundred thousand pages of content, but the URL contains the word forum, which is exactly what the website was to begin with, but has become so much more. It leads advertisers and potential members to all the wrong conclusions. Both myself and my community want a new name that better reflects who we are and what we offer.

We settled on a name but it was already taken by a website, already established within our niche, it had good content and PR. We come to a deal and acquired the new website, who's name we'll be using. It works for the that the new domain is already established as I'd not 301 redirect to a brand spanking new domain without first establishing it.

However, the new website and URL I acquired has been established at subdomain.domain.com rather than www.domain.com which is definitely what we'll be using. I would like to establish the www. of the new domain before I go ahead and 301 redirect our current URL to this new one.

At first I figured it was quite straight forward, 301 redirect the newly acquired websites subdomain to www.?

BUT at no point, do I want to lose the content or links of the newly acquired domain. Both the new and old website run from powerful CMS, with complex .htaccess files. They can't both coexist at www.newdomain.com, at least not without lots and lots of messing around.

I figured rather than 301 redirecting the new website from subdomain to www.newdomain.com I might as well 301 redirect it to www.newdomain.com/randomfoldername where it can stay and not interfere with my website when I finally come to 301 redirect www.currentdomain.com to www.newdomain.com

I really hope I've made more sense this time around as I'd love some feedback, it's given me quite a headache.

Thanks,

g1smd

6:42 am on Sep 25, 2009 (gmt 0)

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



Whatever you do make sure that redirects get from old to new in just one hop. Avoid a redirection chain for any and all requests.

Make sure that the response is 301, not 302.

It is also not a good idea to 'funnel' a large number of redirects to a single destination URL. It is best to arrange redirects so that the request for a 'page' on the old domain is redirected to the same, or a related, page on the new domain.

realmaverick

6:50 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is best to arrange redirects so that the request for a 'page' on the old domain is redirected to the same, or a related, page on the new domain.

I agree. Though there are thousands of pages to cater for. But possibly worth taking the time to do. hmm

The pages on the new domain have links to related resources as well as other links to related content internally. My idea was to just have one main navigation link that went to /

realmaverick

7:05 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've just been playing with the redirect and come up with this:

RewriteCond %{HTTP_HOST} ^subdomain\.newdomain\.com

RewriteCond %{REQUEST_URI}!^/newfolder/

Rewriterule ^(.*)$ /newfolder/$1 [L]

Which does what I want, but is it the best method?

btw

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

will not work. It redirects from subdomain.example.com to www.example.com rather than to www.example.com/folder?

jd01

7:24 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ahhhhh...
Sounds simple.

You have two options I see:
1.) Leave subdomain.example.com as is.
Combine the two .htaccess files into one.
Put the most accessed domain's .htaccess file on top.
Count the rules in the file.
(Carefully. NOT Conditions. Rules Only.)

Add this rule to the top of the .htaccess file:
(Assuming www.example.com's Mod_Rewrite is on top.)

RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$
RewriteRule .? - [S=NumberOfRulesInTheOriginalFile]

This tells Mod_Rewrite to Skip the number of rules following S= for subdomain.example.com and continue processing for all other domain / subdomain variations. If you put the Mod_Rewrite for subdomain.example.com on top, you would simply change it to:

RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule .? - [S=NumberOfRulesInTheOriginalFile]

2.) Redirect subdomain.example.com to something like www.example.com/subdomain/ with something like:

RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$
RewriteRule .? http://www.example.com/subdomain%{REQUEST_URI} [R=301,L]

Then drop the .htaccess from subdomain.example.com into the directory /subdomain/ and change the root .htaccess to what you will use for www.example.com. (Keep in mind, you will probably need to adjust the 'subdomain' .htaccess slightly to function properly in the directory, rather than the root.)

Either way, a rule or two in your .htaccess is all you should need, and a link on the home page for older browsers, which do not send a host header and will probably end up at www.example.com with 'Looking For Subdomain.Example.Com? Click Here' might be a good idea...

As far as the timing goes?
I'll leave that to you.

ADDED:
We were posting at the same time, so I'm just now reading yours... There could be some redundancy or unnecessary information in what I said.

jd01

7:29 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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

Hmmm... It almost sounds like a rule order issue to me, because it should work correctly. Put it at the top, and if it still gives you issues, try adding this rule after:

RewriteRule ^folder/ - [L]

realmaverick

7:33 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks so much jd01.

For some reason.

RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$
RewriteRule .? http://www.example.com/subdomain%{REQUEST_URI} [R=301,L]

goes to http://www.example.com and won't goto the subdomain and so I have to add

Rewriterule ^(.*)$ /subdomain/$1 [L] but then I think it will be classed as 2 redirects and I know Google won't like that.

realmaverick

7:35 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We posted together again. I'll give that a go now, thanks.

edit: I've just tried but it still won't redirect to the folder.

I've tried with the .htaccess in both public_html and also /subdomain

That's the only info in the htaccess.

jd01

7:43 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah, remember, when you 301 you create a new request, so the 'New' URL is reprocessed by the root .htaccess file. If there is some sort of conflict between the URL you want to end up at and the root .htaccess file and you want to run off the one in the /subdirectory/ directory, you will need to tell the .htaccess file on the root to stop processing if the /subdirectory/ directory is requested... That's what the second rule I said to try adding does.

RE your last post: Fascinating.
Let me think a minute.

That's the only rule in there?

jd01

7:45 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are there rewrites / redirects in the httpd.conf file?

realmaverick

7:46 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That makes sense. Though it doesn't make sense why it won't honour it. My head is really starting to hurt. Sometimes the most simple of things, end up becoming a nightmare.

realmaverick

7:48 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Random thought. Would the fact we're using litespeed effect it?

jd01

7:49 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



LOL... I know what you mean.

The files are processed in order.
httpd.conf => root .htaccess => directory .htaccess

So a rule in the httpd.conf file will always 'override' the .htaccess file rules.

jd01

7:51 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Would the fact we're using litespeed effect it?

Not sure what that is...

realmaverick

8:02 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



litespeed is an apache alternative. It's just faster.

I wonder if something in the CMS setup is overriding stuff...

RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/test/$1 [R=301,L] actually redirects to the folder but keeps adding testtesttesttesttest to the url until the browser gives up. My goodness I suck with htaccess!

[edited by: Robert_Charlton at 7:26 pm (utc) on Sep. 25, 2009]
[edit reason] changed to example.com - it can never be owned [/edit]

jd01

8:17 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I wonder if something in the CMS setup is overriding stuff...

That or lightspeed would be my guess. You're trying to do some really basic stuff and it should be working... It's not your mod_rewriting ability if you only have one rule in the file or you put what I told you to in and that was the only thing in there and it didn't work. The worst you should expect from mine is a 500 server error, and in looking at it I don't see a server error. It should Not do what you are describing...

If what I sent you really redirected to http://www.example.com without a / when you used %{REQUEST_URI} then there is a configuration on your server that is different than Apache, which would indicate to me lightspeed is part of your issue, because with standard Apache, the preceding / should be included in %{REQUEST_URI}, even in the .htaccess file.

jd01

8:22 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I wonder if there is a variable / back-reference difference in the server and you are really not passing the information, so you are being redirected to the root, because %{REQUEST_URI} does not exist, and $1 is not the correct back-reference for your server?

Just for fun, maybe put up a PHP page EG test.php with <?=$_SERVER['REQUEST_URI']?> and see what you get. It should be the same as you get in the .htaccess with Mod_Rewrite. (It should 'echo' /test.php)

realmaverick

9:32 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok fixed it!

Probably a stupid error on my part. I had tried the htaccess inside /public_html/ (www.) and also /public_html/folder/ where the files for the domain live.

I thought the subdomain was mapped to public_html however it was mapped to public_html/subdomain/. The htaccess needed to be in public_html/subdomain/

Now at 10:32am, 2 days after waking up, I can sleep! woo.

Thanks so much for your help jd01

jd01

9:59 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No Problem... I've been there myself.
Glad you got it working and I could help a bit.

Use the code I posted it's way more efficient than what you have but that's a discussion for the Apache forum ;)

realmaverick

10:58 pm on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I used the code you posted, works great thanks.

Somehow, somewhere between my fiddling with the htaccess, Google indexed the homepage as [subdomain.domain.com...] ... crap.

I don't think I can easily add a 301 for this, as it doesn't really exist anywhere. Shall I leave it and wait for Google to realise or should I take action?

jd01

12:45 am on Sep 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should be able to remove the 'start anchor' ^ from the Condition you are using:

RewriteCond %{HTTP_HOST} subdomain\.example\.com$

It changes the match from 'exactly' subdomain.example.com to 'ends with' subdomain.example.com.

realmaverick

2:39 am on Sep 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey jd, I tried that but it seemed the htaccess wouldn't effect that particular subdomain, so I created the subdomain www.subdomain.domain.com it worked.

So we're all set now. Now just to figure out how long to let it settle before 301 my main to to www.domain.com! :D

Thanks again for all your help with this. htaccess for me, is one of my biggest nightmares.

jd01

2:49 am on Sep 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks again for all your help with this. htaccess for me, is one of my biggest nightmares.

Yeah, it took me quite a while to really get into it, and we should both really be thanking jdMorgan and WebmasterWorld too, because I mainly learned Mod_Rewrite by reading jdMorgan's posts here in the Apache Forum! [webmasterworld.com]

I'm glad you got things working...

Personally, as far as timing goes, I would probably just wait for the redirects to kickin in the results and then make the move, but it's not my neck on the line, so use your best judgment... I actually usually try to do what the 'normal' person who doesn't 'over think it' would, because that's the 'most natural' thing to do and 'natural behavior' seems to count. (I might even just do it all at once, especially with a 'type in' user-base who know where the site is, but again, it's not my decision or traffic.)

Edited: Couldn't type what I meant or wanted to say repeatedly.

realmaverick

4:46 am on Sep 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Edited: Couldn't type what I meant or wanted to say repeatedly.

You must have caught the bug I had yesterday.

I'm definitely with you on "doing things naturally", helps with my impatience too. Perhaps go for the middle ground, wait for the first lot of redirects to kick in, 301 my current domain, close my eyes and pray to Google god to forgive me for my sins!

jd01

5:16 am on Sep 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



LMAO