Sunday, October 5, 2014

iis 7.5 - Using IIS 7.5 URL Rewrite, how can I redirect all requests not from a particular subdomain to a specific page?



I'd like to use the URL Rewrite module in IIS 7.5 to redirect all requests not from a particular sub-domain (x.domain.com) to a specific folder/file.



For example, these should work as-is:




x.domain.com
x.domain.com/asdf


While anything like these:



y.domain.com
y.domain.com/asdf
domain.com

domain.com/asdf


Should redirect to a specific page like this (exact URL, not dependent upon sub-domain used):



domain.com/a


Unfortunately I can't get the rule configured correctly, as while it matches correctly, most of the time, when it does it just results in a redirect loop. (I know I should put the faulty rules I have setup now, but they're not even consistently resulting in a redirect loop.)




Setting up another Web site in IIS that matches www.domain.com and domain.com is the easy solution, but I'd much rather have one Web site that handles it all and redirects.



What's the correct setup to get this behavior (either using the UI or adding it to the Web.config directly).



Thanks!


Answer



Since you haven't posted your existing rule (the one that results in redirect looping), I can't tell you why it doesn't work. I can tell you what should work though:







   

 

 








 

 



Here we have to rules, one to rewrite all requests where the url matches domain.com except for host headers exactly matching x.domain.com and domain.com (to avoid looping).



The second rule matches requests for exactly domain.com and to any other place than /a/ and redirects them if necessary



No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...