Forum Moderators: phranque

Message Too Old, No Replies

Url Rewrite issue in IIS MOD REWRITE

Url Rewrite

         

manojatdelhi

6:49 am on Jul 17, 2009 (gmt 0)

10+ Year Member



I have a below code in mod-rewrite.txt

RewriteEngine On
RewriteRule /\.htaccess$ - [F]

RewriteCond %{HTTP_HOST} !www\.domainAinfo\.com$
RewriteRule ^(.*)$ http://www\.domainAinfo\.com$1 [R=301,L]

RewriteRule ^/schools/index.aspx$ /schools/english-language.aspx [R=301,L]
RewriteRule ^/about/Contact.aspx$ /about/contact.aspx [R=301,L]

As you can see that above is using www.domainAinfo.com domain for rewriting. I want one more domain www.domainB.com with below configuration to be written in same mod-rewrite file.

RewriteCond %{HTTP_HOST} !www\.domainB\.com$
RewriteRule ^(.*)$ http://www\.domainB\.com$1 [R=301,L]

RewriteRule ^/schools/index.aspx$ /schools/eng-lang.aspx [R=301,L]
RewriteRule ^/about/Contact.aspx$ /about/contactdetails.aspx [R=301,L]

So my complete mod-rewrite.txt file will be given as below:

RewriteEngine On
RewriteRule /\.htaccess$ - [F]

RewriteCond %{HTTP_HOST} !www\.domainAinfo\.com$
RewriteRule ^(.*)$ http://www\.domainAinfo\.com$1 [R=301,L]

RewriteRule ^/schools/index.aspx$ /schools/english-language.aspx [R=301,L]
RewriteRule ^/about/Contact.aspx$ /about/contact.aspx [R=301,L]

RewriteCond %{HTTP_HOST} !www\.domainB\.com$
RewriteRule ^(.*)$ http://www\.domainB\.com$1 [R=301,L]

RewriteRule ^/schools/index.aspx$ /schools/eng-lang.aspx [R=301,L]
RewriteRule ^/about/Contact.aspx$ /about/contactdetails.aspx [R=301,L]

I tried this but is it only responding to first domain www.domainAinfo.com.

Is it possible to control two domain with same rewriterule in same mod-rewrite.txt file.

Please suggest what I can do to solve this issue. I will be very grateful for your help!

[edited by: jdMorgan at 3:10 pm (utc) on July 17, 2009]
[edit reason] examplified domains, de-linked [/edit]

jdMorgan

2:57 pm on Jul 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is a basic logic problem... "!" means "NOT". So the first rule affects anything that is NOT domain A, and the second affects anything that is NOT domain B.

Therefore, all domain B requests will get redirected to domain A.

Use a positive-logic match to the hostname, or exclude each from the other's rule.

Also, if you are creating a redirect using [R=301] then you must include the domain in the substitution URL, that is, "http://domainA.com/schools/english-language.aspx [R=301,L]"

Jim