Wildcard subdomains to different pages

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 3
Joined: 01 Apr 2013, 10:58

Wildcard subdomains to different pages

01 Apr 2013, 11:06

I was able to redirect all sub domains to specific page (a.aspx) with the following rule:

RewriteCond %{HTTP_HOST} !^(www\.)?site\.com$ [NC]
RewriteRule ^(.*)$ /a.aspx?$1 [L]

now i need to redirect all *.site.com/[some number]/ to b.aspx i did it with following rule

RewriteCond %{HTTP_HOST} !^(www\.)?site\.com/(\d*)/$ [NC]
RewriteRule ^(.*).site.com/(\d*)/$ /b.aspx [L]

but its not working, i tried to place it above previous rule and also tried with only ^(.*)(\d*)/$ but neither of them works, the rule redirecting to the a.aspx or to the main page.

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

Re: Wildcard subdomains to different pages

01 Apr 2013, 11:18

Hello,

you need also to consider the order of the rules:

Code: Select all
RewriteCond %{HTTP_HOST} !^(www\.)?site\.com$ [NC]
RewriteRule ^\d+/(.*)$ /b.aspx?$1 [NC,L]

RewriteCond %{HTTP_HOST} !^(www\.)?site\.com$ [NC]
RewriteRule ^(.*)$ /a.aspx?$1 [NC,L]


Regards
Andrew

User avatar
Posts: 3
Joined: 01 Apr 2013, 10:58

Re: Wildcard subdomains to different pages

01 Apr 2013, 11:31

Sorry, Its not helping, i need to be able to catch all *.site.com/(\d*)/ and redirect to b.aspx, in your example you have removed the (\d*) that part from cond line

User avatar
Posts: 3
Joined: 01 Apr 2013, 10:58

Re: Wildcard subdomains to different pages

01 Apr 2013, 14:55

ok, the next rule its working fine, but its also catches the www subdomain, i dont understand why:

RewriteCond %{HTTP_HOST} !^(www\.)?site\.com/$ [NC]
RewriteRule ^(.*)/(\d*)/$ /3.aspx [NC,L]

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

Re: Wildcard subdomains to different pages

01 Apr 2013, 22:36

Instead of
Code: Select all
RewriteCond %{HTTP_HOST} !^(www\.)?site\.com$ [NC]


I'd use
Code: Select all
RewriteCond %{HTTP_HOST} !^www\.site\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.site\.com$ [NC]


Regards
Andrew

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 12 guests