Solved

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

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

Accepted Solution

by:
arnold earned 500 total points
Comment Utility
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
Comment Utility
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 76

Expert Comment

by:arnold
Comment Utility
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
Comment Utility
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
Comment Utility
It worked like a charm!  Thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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). #…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

8 Experts available now in Live!

Get 1:1 Help Now