Forum Moderators: phranque

Message Too Old, No Replies

Redirect old domain to specific page on main domain?

         

mountainsoft

8:45 pm on Oct 17, 2012 (gmt 0)

10+ Year Member



I have a domain name I am no longer using, but would like to redirect all traffic from that site to a specific page on my main site.

For example, if a user visits: www.oldsite.com

They would be redirected to: www.mainsite.com/page.htm

So far, I have URL forwarding setup on the domain name that sends requests to my main domain. Then I have the following in my htaccess file to send them to the specific page:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.oldsite.com$ [NC]
RewriteRule ^(.*) /page.htm [R=301,L]


This works great for the old domain name, but if the visitor tries to access one of the pages I used to have on the old site, it redirects to something like this:

www.mainsite.com/oldpage.htm/page.htm

How can I strip out everything but the old domain name (for that domain only) before redirecting to the new page.htm? I don't care about any of the old pages, I want everything from that domain directed to the new page.

g1smd

8:50 pm on Oct 17, 2012 (gmt 0)

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



Escape the literal periods in the RewriteCond RegEx pattern.

Your rule fails to redirect non-www requests for the old site (or creates a double redirect for those requests).

The rule target should include the new hostname.

mountainsoft

10:40 pm on Oct 17, 2012 (gmt 0)

10+ Year Member



I found a different way of handling this that seems to work much better:

On my name server (namecheap.com), I use their URL forwarding to do a 301 redirect to:

www.mainsite.com/olddomainname

"olddomainname" can be anything as long as it's not a page or folder that exists on my main site.

Then a simple RewriteRule redirects it again to the page I wanted:

RewriteRule olddomainname http://www.mainsite.com/page.htm [R=301]


I have run several tests and this seems to work great:

oldsite.com
oldsite.com/index.htm
oldsite.com/folder/index.htm
www.oldsite.com
www.oldsite.com/test/folder/test.htm

All redirect as I had hoped to:

www.mainsite.com/page.htm

g1smd

10:45 pm on Oct 17, 2012 (gmt 0)

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



redirects it again

You absolutely do not want a double redirect.

mountainsoft

11:05 pm on Oct 17, 2012 (gmt 0)

10+ Year Member



Yes, according to wheregoes.com, the old domain redirects twice, as expected.

1. The name server redirects to my main web site.

2. My rewriterule redirects it on to the appropriate page.

Since the old domain is not hosted, I don't know of any way to avoid this. I tried forwarding directly to the new page on my main site, which works OK for just the domain name. But any links to old web pages that existed on the old domain end up with a weird blend of old site, new page, and old page (causing a 404 error).

Unless there is a more elegant method I am not aware of, my approach does what I wanted. I am no longer using the old domain, so I just want to catch old links that may still point to that domain.

lucy24

11:42 pm on Oct 17, 2012 (gmt 0)

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



Why don't you have a single conditionless redirect on your old site that says simply

RewriteRule .* http://www.example.com/page.html [R=301,L]

? That's assuming for the sake of discussion that you really want to redirect all requests to the same page. Neither the host nor the DNS need to get involved.

mountainsoft

12:01 am on Oct 18, 2012 (gmt 0)

10+ Year Member



Lucy,

The old site no longer exists (no web host for the htaccess file). All I have is the old domain name which my name server allows me to redirect to another URL.

Redirecting to the new page directly works for the domain name, but not for pages that used to exist on the old site (which do not exist on my main site). The method I came up with works fine for all variations.

Here's a nice article on chained redirects, including a video from Matt Cutts. I don't think my two redirects will be a big issue.

[jamesburton.net ]

g1smd

7:45 am on Oct 18, 2012 (gmt 0)

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



Why don't you point the old domain name at the same hosting as the new site and then in the htaccess file there do the redirect when the visitor requested any page on the old site?

The code you posted in the OP with the corrections I noted in the very next post would fix it.

Doing that will result in a one-hop redirect to the correct location.

mountainsoft

2:43 am on Oct 21, 2012 (gmt 0)

10+ Year Member



Hmm... I didn't realize you could point two domains to the same host. Unfortunately, after wrestling with DNS name servers for a couple days, I discovered my hosting account only allows one domain per host (unless I upgrade to their more expensive hosting plans). I'll stick with my two redirect method. Thanks for the info!