Multiple external files for url rewrite under web.config

2.8k Views Asked by At

Earlier I wanted to keep the redirects out of web.config, because I have many rewrite rules. I was successfull in doing that by using

<rewrite>      
      <rules configSource="RewriteRules.config" />
</rewrite>

Now the problem is this file is already having many rules, and I am going to use another set of large amount of rules for another domain pointed to same base code. So I want to keep rules for both files on different files like:-

<rewrite>      
          <rules configSource="RewriteRules_a.config" />
          <rules configSource="RewriteRules_b.config" />
</rewrite>

which is not allowed, can anyone suggest how can i fix this situation?? Please note both domains will have different rules and domain addition can be more too in this project.

Any suggestions will be appreciated ...

1

There are 1 best solutions below

0
On

Can you use create multiple files (for development only) and create post-build rules that concatenate them all into the single rewrite.config file?

This way you can split them into multiple files and version control them during development and the post-build will aggregate them into one file for production purposes.

Does the second domain point to the same application in IIS? If they are different applications you could use the config transformation capabilities of VS to have a single file per domain and only deploy the file you need on each application: http://www.hanselman.com/blog/SlowCheetahWebconfigTransformationSyntaxNowGeneralizedForAnyXMLConfigurationFile.aspx