views:

270

answers:

1

Hi,

I have a below code in mod-rewrite.txt

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

RewriteCond %{HTTP_HOST} !www\.espireinfo\.com$
RewriteRule ^(.*)$ http://www\.espireinfo\.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.espireinfo.com domain for rewriting. I want one more domain www.rai.com with below configuration to be written in same mod-rewrite file.

RewriteCond %{HTTP_HOST} !www\.rai\.com$
RewriteRule ^(.*)$ http://www\.rai\.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\.espireinfo\.com$
RewriteRule ^(.*)$ http://www\.espireinfo\.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\.rai\.com$
RewriteRule ^(.*)$ http://www\.rai\.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.espireinfo.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!

A: 

You want to have one server behave as two different servers by default, it cant do that.

You have to pick one to be the default for the 301 redirect. then keep only one of those sections.

Then add the correct condition on the page re-writes. Thus for espireinfo being the defualt

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

# espireinfo is the default server
RewriteCond %{HTTP_HOST} !www\.espireinfo\.com$
RewriteCond %{HTTP_HOST} !www\.rai\.com$
RewriteRule ^(.*)$ http://www\.espireinfo\.com$1 [R=301,L]

# espireinfo.com rewrites
RewriteCond %{HTTP_HOST} www\.espireinfo\.com$
RewriteRule ^/schools/index.aspx$   /schools/english-language.aspx [R=301,L]
RewriteCond %{HTTP_HOST} www\.espireinfo\.com$
RewriteRule ^/about/Contact.aspx$   /about/contact.aspx [R=301,L]

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

That is unless I've mistaken your domain name rewrites, ie if you are actually trying to force www prefix.

Simeon Pilgrim
Thanks Simeon! I have a big bunch of rewrite rules for espireinfo and few for rai. do I need to write RewriteCond %{HTTP_HOST} www\.espireinfo\.com$ before every url rewrite for espireinfo.com, then what about the www.rai.com url rewrites
MKS
True, the rai.com rules should also have a Cond each. As the espireonfp.com is still reading those rules. But if you have a large number of Rules it's a cut-n-paste job, Another option might be to put all your simple rewrites in a rewritemap, then you'll only need one Cond for the lot. http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritemap
Simeon Pilgrim