Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternate Web.Config for IIS7 Rewrite Module Rules

Is it possible to move the rules created by the IIS7 rewrite module from the root web config into its own web config file like you can with appsettings and if so how?

like image 620
beckelmw Avatar asked May 28 '09 22:05

beckelmw


People also ask

How do I fix the URL Rewrite module in IIS?

IIS Rewrite Module Problem Uninstall the Rewrite Module from Windows Features. Go to the Web Platform Installer. Pick Url Rewrite from Products | Server section and install. Restart IIS.


2 Answers

I can't seem to get it working, but the way it's described is:

<rewrite>
   <rewriteMaps configSource="external.config">
   </rewriteMaps>
</rewrite>

Then in the external.config file add your rules:

<rewriteMaps>
  <rewriteMap ...
  ...
</rewriteMaps>

You have to do this with the entire rewriteMaps section: according to this forum post, you can't do this with the rewriteMap: http://forums.iis.net/t/1154113.aspx

like image 181
willoller Avatar answered Sep 25 '22 11:09

willoller


This works for me in web.config:

<system.webServer>
    <rewrite>
      <rules configSource="web.rules.config" />
    </rewrite>
</system.webServer>

One cool thing is that the IIS Configuration Editor respects this external file when you edit the rules and writes the changes back to the external file.

If you put:

<system.webServer>
    <rewrite configSource="web.rules.config" />
</system.webServer>

it won't work, you get HTTP error 500.19 Internal server error:

Error Code:   0x8007000d
Config Error: Unrecognized attribute 'configSource'

Can anyone point to the definitive MSDN help page on the rewrite element and the configSource attribute? The MSDN article on system.webServer does not mention the rewrite element and I can't find an MSDN page via google.

like image 32
JohnC Avatar answered Sep 25 '22 11:09

JohnC