Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL Rewrite and IIS Express: some rules work, some don't

I'm using IIS Express to develop an MVC 3 application which is doing some URL rewriting in web.config. I have ran into a bit of an oddity where some of the rules work perfectly, while others fail.

For example this one works:

<rule name="Remove ETag">
 <match serverVariable="RESPONSE_ETag" pattern=".+" />
 <action type="Rewrite" value="" />
</rule>

(source: https://stackoverflow.com/a/8089525/88709)

This one doesn't (gives Unrecognized attribute 'url' in the second line):

<rule name="Remove trailing slash" stopProcessing="true">
  <match url="(.*)/$" />
  <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  </conditions>
  <action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>

(source: http://blogs.iis.net/ruslany/archive/2009/04/08/10-url-rewriting-tips-and-tricks.aspx)

According to Introducing IIS Express, by ScottGu, IIS Express enables a full web-server feature set – including SSL, URL Rewrite, Media Support, and all other IIS 7.x modules.

I was inclined to believe that maybe the URL Rewrite module that ships with IIS Express is the 1.0 version, not 2.0. So I installed URL Rewrite Module 2.0, but I still get the same error.

Does anybody have a clue why this happens? In case it matters, my setup is Visual Studio 2010 SP1, IIS Express 7.5.1070, ASP.NET MVC 3.

like image 641
Daniel Liuzzi Avatar asked Oct 24 '22 13:10

Daniel Liuzzi


1 Answers

The problem was that I placed the <rule> in the wrong node; 'Remove trailing slash' rule is supposed to go inside <rules></rules>, but I incorrectly placed it in <outboundRules></outboundRules> (which BTW is where the 'Remove ETag' rule goes).

like image 149
Daniel Liuzzi Avatar answered Oct 31 '22 10:10

Daniel Liuzzi