How to ban Internet Explorer 6 from your Site Using the IIS7 Url Rewrite Module

Submitted on Jul 11, 2009, 3:39 a.m.

UPDATE 12/07/2009 - As Shirley Boyle sang - "I dreamed a dream". The exercise below was great for learning how to use the IIS7 Url Rewrite Module - but there is a long list of user agents that contain the string "compatible; MSIE 6.0;" including the MSN spider and some transparent proxies. Internet Explorer 6 is the browser that refuses to die. :-(

ORIGINAL POST - This one took a little while to figure out along with a careful read of the reference docs for the IIS7 Url Rewrite Module. I was banging my head against the wall for a few minutes with {USER_AGENT} before reading the fine print… the HTTP prefix bit in particular.

All dash (“-”) symbols in the HTTP header name are converted to underscore symbols (“_”).
All letters in the HTTP header name are converted to capital case.
“HTTP_” prefix is added to the header name.
For example, in order to access the HTTP header “user-agent” from a rewrite rule, you can use the {HTTP_USER_AGENT} server variable.

And here’s the result…

1<rule name="BlockIE6" stopProcessing="true">
2 <match url=".*" />
3 <conditions>
4 <add input="{HTTP_USER_AGENT}" pattern="MSIE 6" />
5 <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
6 <add input="{URL}" negate="true" pattern="ie6" />
7 </conditions>
8 <action type="Redirect" url="ie6" redirectType="Permanent" />

It’s really really important that you do two things: 1) Prevent the redirect from redirecting static content – like script files and style sheets, ala the {REQUEST_FILENAME} negative condition, and 2) You also check the Url to see if it’s the redirected Url – i.e. they’ve already been redirected – otherwise you’ll get an endless redirect loop. In this case I’m sending them to the url “ie6” which is an action on a route in ASP.Net MVC – displaying a download page with some ‘alternatives’ :-)