maxxd Posted October 11, 2016 Share Posted October 11, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/302316-combining-domain-names-with-rewriterule-or-redirect/ Share on other sites More sharing options...
kicken Posted October 11, 2016 Share Posted October 11, 2016 Do you want to keep the separate domain URL's or do you want to just redirect to the one domain? In other words if someone goes to domainB.com should the browser continue to show domainB.com or switch to domainA.com/domain-b-landing-page? Quote Link to comment https://forums.phpfreaks.com/topic/302316-combining-domain-names-with-rewriterule-or-redirect/#findComment-1538201 Share on other sites More sharing options...
maxxd Posted October 11, 2016 Author Share Posted October 11, 2016 It should forward to domainA.com/domain-b-landing-page. PS - sorry for the silly domain names. Client property, and of course it all sounded better in my head while I was composing my post... Quote Link to comment https://forums.phpfreaks.com/topic/302316-combining-domain-names-with-rewriterule-or-redirect/#findComment-1538206 Share on other sites More sharing options...
kicken Posted October 12, 2016 Share Posted October 12, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/302316-combining-domain-names-with-rewriterule-or-redirect/#findComment-1538208 Share on other sites More sharing options...
maxxd Posted October 12, 2016 Author Share Posted October 12, 2016 Thanks, kicken - I'll give that a try this morning! Quote Link to comment https://forums.phpfreaks.com/topic/302316-combining-domain-names-with-rewriterule-or-redirect/#findComment-1538214 Share on other sites More sharing options...
maxxd Posted October 14, 2016 Author Share Posted October 14, 2016 kicken, thanks much - that worked perfectly! Quote Link to comment https://forums.phpfreaks.com/topic/302316-combining-domain-names-with-rewriterule-or-redirect/#findComment-1538290 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.