Wildcard subdomains to different pages
5 posts
• Page 1 of 1
- dimitrykashin
-
- Posts: 3
- Joined: 01 Apr 2013, 10:58
Wildcard subdomains to different pages
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.
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.
- HeliconAndrew
-
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Wildcard subdomains to different pages
Hello,
you need also to consider the order of the rules:
Regards
Andrew
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
- dimitrykashin
-
- Posts: 3
- Joined: 01 Apr 2013, 10:58
Re: Wildcard subdomains to different pages
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
- dimitrykashin
-
- Posts: 3
- Joined: 01 Apr 2013, 10:58
Re: Wildcard subdomains to different pages
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]
RewriteCond %{HTTP_HOST} !^(www\.)?site\.com/$ [NC]
RewriteRule ^(.*)/(\d*)/$ /3.aspx [NC,L]
- HeliconAndrew
-
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Wildcard subdomains to different pages
Instead of
I'd use
Regards
Andrew
- 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
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 12 guests