Solved

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

Posted on 2013-12-02
5
332 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now