IIS7 urlrewrite module - Rules in external xml file
Solution 1
Yes, you can use the configSource
attribute to point to an external file like you can with other web.config sections. In the web.config:
<rewrite>
<rules configSource="Rewrite.config" />
</rewrite>
And in the rules config file:
<rules>
<rule name="some rule">
<!-- rule details here --->
</rule>
</rules>
You can still even use the IIS manager to edit rules and it'll just work. One minor caveat with this approach: when you make a change and save an external file like this, it will not recycle the application like making a change to the web.config will. So if you're editing a rule and want to see it take effect, you need to manually poke the web.config by making an edit and saving it.
Another reference: Moving IIS7 url rewrite section out of the web.config file
Solution 2
You can use the sample URL Rewrite providers that include one for storing those in a separate file, see: http://www.iis.net/learn/extensions/url-rewrite-module/using-custom-rewrite-providers-with-url-rewrite-module
Related videos on Youtube
opaera
Updated on July 16, 2020Comments
-
opaera almost 4 years
I'm using IIS7 UrlRewrite module. I set up my rules in the web.config
<system.webServer><rewrite>
section. I want to know if there's a way to define the rules in one external xml file instead of in web.config file. Thanks.-
Remy over 13 yearsNot that I know of. Why would you need that?
-
magnattic over 10 years@Remy: Late response, but it increases readability of the web.config when you have a lot of rewrite rules. That's the reason for me anyway.
-
Riccardo Bassilichi over 6 yearsin IIS >= 7.5 remember to install URL Rewrite component from here iis.net/downloads/microsoft/url-rewrite
-
-
magnattic over 10 yearsAre you sure about the application not being recycled on external changes? There is another property on config sections called RestartOnExternalChanges and it defaults to true.
-
Kurt Schindler over 10 years@atticae I believe RestartOnExternalChanges applies only to custom defined <section> elements, which rewrite rules are not. forums.iis.net/t/1155629.aspx I'm not sure if anything has changed since then, this thread is from 2009...
-
Valerio Gentile over 8 yearsUnfortunately the IntelliSense in Rewrite.config does not work. Is there any way to solve this issue?
-
Blue Clouds about 8 yearsbut that is for mappings. Config is used for another purpose, to set custom rules. sometimes we need to use a reg expression to all the url mappings we need then the only way is to include it in config.