Storing URL rewrite mappings in a separate file
When using rewrite maps in IIS URL Rewrite it is very common to have a very large number of entries in a rewrite map. In order to avoid cluttering the configuration file - web.config - with this configuration data the rewrite maps can be defined in a separate configuration file. That file can then be referenced from the web.config file. This post provides an example of how this can be done.
Create a file called rewritemaps.config in the same directory where web.config file is. Open that file in notepad and add the following:
<rewriteMaps> <rewriteMap name="Redirects"> <add key="/oldurl" value="/newurl" /> <add key="/otheroldurl" value="/othernewurl" /> </rewriteMap> </rewriteMaps>
Save this file and then open web.config file in notepad. In the web.config file add the following inside of the <rewrite> section:
<rewriteMaps configSource="rewritemaps.config" />
The configSource attribute tells IIS configuration that the <rewriteMaps> section is defined in a separate file rewritemaps.config. This referenced section can be now uses as if it was defined in the same web.config file. Also, the IIS Manager UI will work well with this referenced file: when you modify or add entries to the rewrite map they will be stored in the rewritemaps.config file.
Here is a complete example web.config file that uses the rewrite map from referenced configuration file:
<configuration>
<system.webServer>
<rewrite>
<rewriteMaps configSource="rewritemaps.config"><rewriteMaps>
<rules>
<rule name="Redirect rule1 for Redirects">
<match url=".*" />
<conditions>
<add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
The same approach can be used for storing rewrite rules in a separate configuration file, e.g.:
<rules configSource="rewriteRules.config" />
1,664 views
ruslany on May 19th 2010 in URLRewrite

Does this also apply to applicationHost.config rules for server level rewrites?
This does not apply to applicationHost.config. It only works with web.config files.
Also, note that if you manually edit rewritemaps.config file by using a text editor then the changes to the file will not take effect until you recycle the IIS application pool. But if you modify the rewrite map entries by using IIS Manager UI then the changes will take effect right away.
Useful information: the maximum allowed size of web.config file by default is 250Mb (100Mb in Vista).
The default can be changed by setting a registry key HKLM\SOFTWARE\Microsoft\InetStp\Configuration\MaxWebConfigFileSizeInKB (REG_DWORD)
More information on this and other registry keys can be found at List of registry keys affecting IIS7 behavior
Is it possible to have a different set of URL rewrite rules on the same domain? For example website.com might have one set of rules, while domain.website.com might have another or add to the already existing rules?
can we have the 301 redirects stored as a separate file too? if yes, how?
thanks
hi
this is my url link
herbal.aspx?link=rejuvenating butea.txt&id=8&h=butea
- i want like this
herbal/butea/rejuvenating butea
can you pl guide me to do. i m very new to iis 7
thank you
nk