Jump to content

Combining domain names with RewriteRule or Redirect?


maxxd

Recommended Posts

Hey y'all.

 

I've got two currently active domains (http://www.domainA.com and http://www.domainB.com) that I'm going to be combining next week. In other words, I'll be updating the DNS records to point to the same IP address. I need http://www.domainB.com to point to http://www.domainA.com/domain-b-landing-page and am not having much luck with RewriteRule or Redirect. I don't know if it complicates things a bit or not, but I also nee http://www.domainB.com/page/ to redirect to http://www.domainA.com/domain-b-landing-page/different-page.

 

Right now (for testing purposes) I've updated my local hosts file to point both the existing domain names to the new IP address, and I can't get http://www.domainB.com to point to the correct page - it only points to the home page of domainA. Any URL with a sub-page from domainB doesn't redirect at all and only returns a 404.

 

I've tried this to no avail:

RewriteCond %{HTTP_HOST} ^domainB.com$
RewriteRule (.*) http://www.%{HTTP_HOST}%/domain-b-landing-page/$1

I'm hoping this makes some sense and somebody can point me in the proper direction.

Link to comment
Share on other sites

Something like this should handle a request to domainB by issuing a redirect to the domainA landing page.

 

RewriteCond %{HTTP_HOST} ^(www.)?domainB.com$
RewriteRule (.*) http://www.domainA.com/domain-b-landing-page/$1 [R=301,L]
It also preserves the path of the original request by appending it to the domainA url. For example `domainB.com/page` would go to `domainA.com/domain-b-landing-page/page`.

 

If your path redirects do not match up like that then you'll have to do them as separate RewriteRule entries before your catch-all entry in order of most-specific to least-specific.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.