Forum Moderators: phranque

Message Too Old, No Replies

Redirecting 301 subdomain to a new domain

301 redirect subdomain

         

drsuccess

8:40 pm on Oct 11, 2006 (gmt 0)

10+ Year Member



I have a subdomain that no longer exists and now has its own domain. But the old subdomain it's indexed on search engines. So I added this tidbit in the .htaccess file, but it doesn't work:


RewriteEngine On
RewriteCond %{http_host} ^(.*)\.subdomain\.olddomain\.com$
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]

I've looked high and low for this, and tried different variations, with no success. Can someone help?

Thanks!

[edited by: jdMorgan at 9:04 pm (utc) on Oct. 11, 2006]
[edit reason] de-linked [/edit]

jdMorgan

9:03 pm on Oct 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As written, the code will only redirect <anything>.subdomain.olddomain.com -- In other words, a sub-subdomain (even if blank) followed by a "." is required.

Is that what you want?

If not, then what do you mean, very specifically, by "it doesn't work"? How did you test, what were the results, and how did those results differ from your expectations?

Jim

The Contractor

9:05 pm on Oct 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



why not just stick the following in the .htaccess root of the subdomain:

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

(I put a space after http:// to delink)

[edited by: The_Contractor at 9:07 pm (utc) on Oct. 11, 2006]

drsuccess

9:54 pm on Oct 11, 2006 (gmt 0)

10+ Year Member



The subdomain doesn't exist anymore. So that won't work.

drsuccess

9:55 pm on Oct 11, 2006 (gmt 0)

10+ Year Member



jd, here's what I want:

[subdomain.olddomain.com...]

No longer exists, and I want people who visit it to go to:

[newdomain.com...]

Hope this helps?

The Contractor

10:05 pm on Oct 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you no longer have control of the old domain/subdomain, how would you redirect traffic to a new domain? Not going to happen.. You need to put the redirect on the old domain and subdomain.

[edited by: The_Contractor at 10:06 pm (utc) on Oct. 11, 2006]

drsuccess

10:16 pm on Oct 11, 2006 (gmt 0)

10+ Year Member



I own both domains. The subdomain has its own domain now. That's the point. I have put an .htaccess in the root folder of the olddomain, which still exists.

Here's an example:

You have a domain:

example.com

You had a forum on it, at:

forum.example.com

But now, you have a new domain:

example-forum.com

So you want to redirect:

forum.example.com to example-forum.com

Does that makes sense?

Edited to add: You still own and run example.com.

[edited by: jdMorgan at 10:20 pm (utc) on Oct. 11, 2006]
[edit reason] Example.com [/edit]

jdMorgan

10:18 pm on Oct 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In that case, the code should be corrected as follows:

RewriteEngine on
RewriteCond %{HTTP_HOST} subdomain\.olddomain\.com
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

As noted, this will only work if the subdomain's DNS record points to your server, and if the server is set up to 'deliver' subdomain requests to the directory in which this .htaccess code resides.

Removing the start- and end- anchoring from the hostname pattern allows it to match <anything_or_nothing>subdomain.olddomain.com<any port number>

Do not feel free to substitute lowercase for uppercase or vice-versa in config code. In many cases it will work, but in many others it won't. Use the case as shown in the Apache directives' documentation for best results and portability across operating systems and Apache versions.

Jim