Max. amount of rewrites in a webconfig file (IIS)

Michèle Merlo 20 Reputation points
2023-03-08T12:05:38.44+00:00

I'm right now struggling to add more rewrites to my webconfig file from the IIS (Windows Server 2012 RS). There are already about 2034 rewrites in the rewritemap, if I add more the IIS runs into a error 500. I've tried adding rewrites that I know have worked before and they lead to the same result.

Is there a known limit how many rewrites the <rewriteMaps> tag allows?

Thanks for the info in advance and have a good day.

Windows development | Internet Information Services
Windows for business | Windows Server | User experience | Other
{count} votes

1 answer

Sort by: Most helpful
  1. Yurong Dai-MSFT 2,846 Reputation points Microsoft External Staff
    2023-03-09T03:21:26.82+00:00

    Hi @Michèle Merlo,

    If the size of the Web.config file exceeds the threshold, IIS will refuse to read it, and the configuration system will generate the error "The configuration file cannot be read because it exceeds the maximum file size". The maximum size of web.config allowed by default is 250KB.

    You can change the registry key HKLM\SOFTWARE\Microsoft\InetStp\Configuration\MaxWebConfigFileSizeInKB to allow a larger web.config. If the value of this key is changed, the process must be restarted. Please refer to this link for more information.

    Besides that, there is another way to manage large web.config file. You can create rewrite maps and store them in separate files. For example, if you have a rewrite map like below, please save it in a file called rewritemaps.config.

    <rewriteMaps>
       <rewriteMap name="Redirects">
         <add key="/fromthisURL" value="/tothisURL" />
         <add key="/fromthisURL2" value="/tothisURL2" />
       </rewriteMap>
    </rewriteMaps>
    

    Then reference it from your web.config file:

    <configuration>
    <system. webServer>
       <rewrite>
         <rewriteMaps configSource="rewritemaps.config"><rewriteMaps>
           <rule name="Redirect rule">
              ...
           </rule>
       </rewrite>
    </system. webServer>
    </configuration>
    

    You can also store rewrite rules in a separate file and then reference it:

    <rules configSource="rewriteRules.config" />
    

    Just like the web.config file, the rewritemaps.config and rewriteRules.config files also have a size limit of 250 KB.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the email notification for this thread.

    Best regards,

    Yurong Dai


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.