Check Domain

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 5
Joined: 17 Jan 2013, 04:19

Check Domain

17 Jan 2013, 04:47

Hi ALL,

I have a problem in redirect URL. Existing i already have some redirect rules for the website. But those rules are only for one domain only. Right now i have two websites with two domain : hk.xxx.com and usa.xxx.com. How can I check it with finding out the domain difference.

my redirect rules only can check the characters after the domain name
For example

RewriteRule ^findus.aspx(.*) /bookmark\-us/ [NC,L,R=301,O]
RewriteRule ^(bookmark\-us/?)(.*) /findus.aspx [NC]

I want to change it too
RewriteRule ^hk.xxx.com/findus.aspx(.*) /bookmark\-hk/
RewriteRule ^(bookmark\-hk/?)(.*) hk.xxx.com/findus.aspx
RewriteRule ^usa.xxx.com/findus.aspx(.*) /bookmark\-usa/
RewriteRule ^(bookmark\-usa/?)(.*) hk.xxx.com/findus.aspx


Thanks for help!

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Check Domain

17 Jan 2013, 10:59

Hello,

To match a certain domain you need to use the following condition in front of a rule:

Code: Select all
RewriteCond %{HTTP:Host} ^hk\.xxx\.com$ [NC]


Regards
Andrew

User avatar
Posts: 5
Joined: 17 Jan 2013, 04:19

Re: Check Domain

21 Jan 2013, 01:13

Hi.

Thanks for your reply.

After use the method you suggest, it works. :D

But i have one more question

If there are several rules that needs to follow the domain name, do i need to write this RewriteCond again according to how many rule i create.

That's

RewriteCond %{HTTP:Host} ^hk\.xxx\.com$ [NC]
RewriteRule ^findus.aspx(.*) /bookmark\-hk/ [NC,L,R=301,O]
RewriteRule ^aboutus.aspx(.*) /About\-hk/ [NC,L,R=301,O]


RewriteCond %{HTTP:Host} ^us\.xxx\.com$ [NC]
RewriteRule ^findus.aspx(.*) /bookmark\-usa/ [NC,L,R=301,O]
RewriteRule ^aboutus.aspx(.*) /About\-usa/ [NC,L,R=301,O]

or

RewriteCond %{HTTP:Host} ^hk\.xxx\.com$ [NC]
RewriteRule ^findus.aspx(.*) /bookmark\-hk/ [NC,L,R=301,O]

RewriteCond %{HTTP:Host} ^hk\.xxx\.com$ [NC]
RewriteRule ^aboutus.aspx(.*) /About\-hk/ [NC,L,R=301,O]


RewriteCond %{HTTP:Host} ^us\.xxx\.com$ [NC]
RewriteRule ^findus.aspx(.*) /bookmark\-usa/ [NC,L,R=301,O]

RewriteCond %{HTTP:Host} ^hk\.xxx\.com$ [NC]
RewriteRule ^aboutus.aspx(.*) /About\-usa/ [NC,L,R=301,O]


Thanks again.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Check Domain

21 Jan 2013, 10:14

hello,

The last one is correct. You use the condition with each rule. However, you may also try to use one of the dynamic rules, for example:


Code: Select all
RewriteCond %{HTTP:Host} ^(hk|usa)\.xxx\.com$ [NC]
RewriteRule ^findus.aspx(.*) /bookmark\-%1/ [NC,L,R=301,O]


Regards
Andrew

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 0 guests