Sunday, January 17, 2016

iis - URL Rewrite Not Firing Properly

I had an url rewrite rule configured at IIS Root (ApplicationHost.config) that redirects www.example.com to HTTPS. The URL Rewrite configuration is setup on an IIS Instance behind a Public Load Balancer of our hosting where our SSL is installed by our hosting provider. The Load Balancer provides us with X-Forwarded-Proto header that sets to http if the original request is in HTTP and https if the original request is in HTTPS.



The Url Rewrite is configured this way:




 Pattern: .*
Conditions: Match All
Input |Type |Pattern
-------------------------------------------------------------
{HTTP_HOST} |Matches the Pattern |www.example.com
{HTTP_X_Forwarded_Proto}|Matches the Pattern |^http$
Action:
Redirect to URL: https://{HTTP_HOST}{REQUEST_PATH}
Redirect Type : 302



The problem is, we had a powershell script that installed in the web server itself to check whether the website is available or not using [System.Net.WebRequest]::Create($siteUrl). The script reports HTTP 200 (OK) most of the time, but sometimes it fails with 404 HTTP Error. Since the PowerShell script is locally executed, it should not have the X-Forwarded-Proto header and never get 404 by IIS.



Is it possible in any way, that URL Rewrite fired when it should not?

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...