Solved

Rewrite Rule from Domain1 to Domain2 with additional redirects for specfic pages

Posted on 2013-12-02
5
333 Views
Last Modified: 2013-12-10
So I have a rewrite to change domain1 to domain2 keeping the page.
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com [NC]
RewriteRule ^(.*)$ http://www.domain2.com/$1 [R=302,NC,L]

Open in new window


However I have additional redirects in the htaccess file for specific pages to redirect them to other pages.  So what I end up with is the rules stop processing after the domain switch.  Is it easier to set up a virtual host for the domain and redirect from there to the appropriate page on the other domain using rewrite rules or am I just missing something simple in the domain switch rule .. I already tried removing "L" in rule.
0
Comment
Question by:iceman19330
  • 2
  • 2
5 Comments
 
LVL 77

Accepted Solution

by:
arnold earned 500 total points
ID: 39691643
You could either copy the page redirects to the new domain, or order the redirects such that the page redirects are evaluated before the domain redirect.

Use rewritecond to test for the page if this condition is matched redirect it directly to the newsite with the page you want there.

How long are you planning on maintaining the OLD domain?
0
 

Author Comment

by:iceman19330
ID: 39691686
OLD domain will be maintained for a month or two before the OLD domain comes back, if that makes sense.  I was asked to do this with taking the OLD domain away and then bringing it back later, not my choice.
0
 
LVL 77

Expert Comment

by:arnold
ID: 39691694
I am uncertain of what your requirements are.  You could add to the new domain virtualhost a serveralias directive referencing/including the old domain and point the old domain to the new domains IP.
This mean each domain has its own IP.

Doing this the way you are heading means that whatever the reason for this one month will require cautious a and painstaking attention to detail.

Presumably, the old site is being revamped.
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 39691748
Assuming you are stuck with old.domain.com and new.domain.com, then arnold's suggestion of reordering the rules is probably the best way.
# rewrite your pages first
# note the lack of [L] on these rules
RewriteRule ^/?thispage.htm$ /thisotherpage.htm [NC]
RewriteRule ^/?foo.htm$ /bar.htm [NC]

# now push to the new domain
# this can't fire first, even without the L, because it will mangle the URL
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com [NC]
RewriteRule ^/?(.*)$ http://www.domain2.com/$1 [R=302,NC,L]

Open in new window

If you have the option of continuing to use old.domain.com and do the work on new.domain.com, that would be ideal.
0
 

Author Closing Comment

by:iceman19330
ID: 39709859
It worked like a charm!  Thanks
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
XAMPP 14 44
PHP Upload using Uploadify 4 96
htaccess file 3 81
How to ensure a smooth transition to Let's Encrypt SSL Cert? 2 72
Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question