Forum Moderators: phranque

Message Too Old, No Replies

Need a 301 redirect for just the blog section of a site

         

horatiub

11:23 am on Feb 21, 2008 (gmt 0)

10+ Year Member


Hello everyone,

I'm having a problem trying to redirect a domain.

My current domain is place at www.old-site.com/blog

and I would like to move it to www.new-site.com

but remember, just the /blog part, the main site stays where it is.

I've tried 2 different methods, one works, the other doesn't

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.old-site.com/blog [NC]
RewriteRule ^(.*)$ http://www.new-site.com/$1 [L,R=301]

it doesn't work. I placed this in the .htaccess found in the root, and not under the /blog

but if I try this code

redirect 301 /blog http://www.new-site.com/

everything works well.

Which one should I use? Is there a difference between the two of them?

Also, since most of my traffic is from Google, I read somewhere that it's a good idea to redirect the pages one by one, but..I have no idea on how to proceed with that.

Thank you

bwnbwn

2:57 pm on Feb 21, 2008 (gmt 0)

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



have you tested to make sure header is sending a 301
[webmasterworld.com...]
before anything else is done this needs to be checked from several urls in the old domain

jdMorgan

3:14 pm on Feb 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One problem is that "/blog" is not part of HTTP_HOST, and must be handled in another RewriteCond or in the RewriteRule itself:

RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^(www\.)?old-site\.com [NC]
RewriteRule ^blog(.*)$ http://www.new-site.com$1 [R=301,L]

Modified to accept "old-site.com" as well as "www.old-site.com" and work with or without trailing slash on "blog".

Note that the pages on the new site may need to be modified to link to www.new-site.com/<page>, and not to www.new-site.com/blog/<page>.

Jim

horatiub

11:42 pm on Feb 21, 2008 (gmt 0)

10+ Year Member



jdMorgan, I am totally lost and at this point, I might have just ruined years of work.

Here is the full scenario:

On my hosted server, I have several website setup. So, basically, public_html is the root, which contains of course the main website and other sites as well, setup this way: site1, site2, etc...
Now, the /blog is obviously found under public_html/blog , which translates to www.old-site.com/blog

The public_html has an .htaccess which is basically empty. The /blog folder, since it's a Wordpress installation, it has it's only .htaccess.

Before we go into the above code that wasn't working, here is what I did so far:

1. I put redirect 301 /blog http://www.newsite.com into the .htaccess in the public_html. By doing that, the old-site.com/blog redirects fine to the new one, but...now the /blog found under a different site, like site1.com/blog redirects also to the new-site.com, which is not something that I want.

2. to avoid all of this, I took the redirect 301 code from the .htaccess in the public_html and I have placed inside the .htaccess found in the public_html/blog, or old-site.com/blog. Now, the redirect works fine and just for that domain.

Now to go further, I am not sure how to do the redirect in the way you explain it in your post, so if you could please help me out with that, I would really appreciate it.

I am beyond desperate now since my Google traffic accounts for 80% of the overall traffic.

[edited by: tedster at 1:09 am (utc) on Feb. 22, 2008]
[edit reason] de-link [/edit]

horatiub

11:43 pm on Feb 21, 2008 (gmt 0)

10+ Year Member



oh, and one more thing, the new site will not have the /blog anymore, it will be just basically www.new-site.com, so therefore, I kept the same permalinks structure so it will be easier.

Marcia

11:54 pm on Feb 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



On my hosted server, I have several website setup. So, basically, public_html is the root, which contains of course the main website and other sites as well, setup this way: site1, site2, etc...

Is that blog, and are the other "sites" in a /subdirectory/ of the old main domain/website, or do they each have their own domain name as add-on domains in the hosting package?

[edited by: Marcia at 11:59 pm (utc) on Feb. 21, 2008]

horatiub

11:59 pm on Feb 21, 2008 (gmt 0)

10+ Year Member



it's a subdirectory of the main domain

the other sites, site1, sites2 are add-ons.

horatiub

3:51 am on Feb 22, 2008 (gmt 0)

10+ Year Member



Marcia, i see that you updated your response: the other sites are add-ons in the hosting package, this one, /blog, is a folder where I have installed Wordpress. So, it's not a separate domain.

Marcia

4:09 am on Feb 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



horatiub, I can't answer your question, but that wasn't clear, and I was curious (for myself) and hoped to clarify it so that whoever comes along who can answer you will have all the particulars they need.

Also, this is exactly why I've gone with multi-domain WHM hosting where each domain has its own /cpanel and /www (and their own stats) and have stayed clear of add-on domains, where additional domains go into sub-folders of the main account domain. I wouldn't know where to begin with add-ons.

Could there be any conflict between what you're putting into mod_rewrite in the root and the WP .htaccess that's in the /blog folder?

horatiub

4:21 am on Feb 22, 2008 (gmt 0)

10+ Year Member



I see. Well, i only placed the redirect 301 in the /blog folder now, since it didnt work properly before, but I'm not sure if it's ok or not

horatiub

6:26 am on Feb 22, 2008 (gmt 0)

10+ Year Member



here is how the server is structured

<snip>

So, basically, the one that I am worry about is public_html/blog.

What I was trying to say about site1/blog was that if I place the redirect 301 /blog [new-domain.com...] in the .htaccess found in the public_html, then it would redirect both, the public_html/blog and site1/blog

To avoid this, I placed the redirect 301 code in the public_html/blog/.htaccess and this was, only that folder gets redirected.

[edited by: jdMorgan at 5:18 pm (utc) on Feb. 22, 2008]
[edit reason] No URLs, please. See Terms of Service. [/edit]

jdMorgan

5:19 pm on Feb 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> Well, i only placed the redirect 301 in the /blog folder now, since it didnt work properly before, but I'm not sure if it's ok or not.

This sounds like a good, simple solution. Are you having any problems, or do you see anything amiss when you check the server response headers?

Jim

horatiub

10:51 am on Feb 23, 2008 (gmt 0)

10+ Year Member



Jim, yeah, that solution works but I have a feeling that it's not the proper one. I would hate to lose some keywords in this process.

the weirdest part is that any mod_rewrite that i tried in the public_html/.htaccess doesn't work, and yes, mod_rewrite is enabled, I tested it.

you said this in an earlier reply

"Note that the pages on the new site may need to be modified to link to www.new-site.com/<page>, and not to www.new-site.com/blog/<page>."

I don't think they need to be modified since i kept the same permalink structure in Wordpress, so instead of having the domain abc.com/blog/ now I have xyz.com so the <page> makes no difference in the end.

jdMorgan

9:07 pm on Feb 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> ...that solution works but I have a feeling that it's not the proper one. I would hate to lose some keywords in this process.

OK, then let me be clear. It is one of three correct solutions, and will not cause problems unless you've not told us some important detail, or mis-typed it. CHanck your server headers thoroughly, and then stop owrrying about it.

> I don't think they need to be modified since i kept the same permalink structure in Wordpress, so instead of having the domain abc.com/blog/ now I have xyz.com so the <page> makes no difference in the end.

I'm not sure what you mean by this (at several levels, but it's irrelevant), but if WP takes care of this by default and you see newdomain.com/ instead of olddomain.com/blog when you hover over a link, then you're OK. If you *do* see olddomain.com/blog when hovering, then it *will* make a difference in the end.

Jim

horatiub

6:43 am on Feb 26, 2008 (gmt 0)

10+ Year Member



Jim, everything seems to be ok with the headers and yes, when typing olddomain.com/blog , it does get redirected to newdomain.com.

but here is the issue. A few days ago, there were about 200 links out of 900 that were indexed by google already, then 2 nights ago, it dropped to like 130 links, it went back up during the day yesterday, maybe 160, and now it's down again to 100. Is this normal?