?
Solved

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

Posted on 2013-12-02
5
Medium Priority
?
347 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 79

Accepted Solution

by:
arnold earned 2000 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 79

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 51

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

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 my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

777 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