locked
Split web.config rewrite rules in separate file RRS feed

  • Question

  • User-1246604461 posted

    My web.config file has become too big and I read here that I can split the web.config rewrite rules in a separate file: http://ruslany.net/2010/05/storing-url-rewrite-mappings-in-a-separate-file/

    So I did this:

    web.config

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

    rewriteRules.config

    I tried below (and I also tried variations without the wrapping configuration, system.webServer, rewrite and rules nodes:

    <configuration>  
    <system.webServer>  
      <rewrite>  
        <rules>  
             <rule name="location_category">
              <match url="^([a-zA-Z0-9-+]+)$"/>
              <action type="Rewrite" url="search.aspx?category={R:1}"/>
            </rule>
        </rules>  
      </rewrite>  
    </system.webServer>  
    </configuration>  
    

    But I get the error 

    500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed.

    How can I split only the rewrite rules in a separate file? And is that separate file limited in filesize again?

    Tuesday, January 14, 2014 4:34 AM

Answers

All replies

  • User1734617369 posted

    Hi,

    To make this work I think that you need to change your rewriteRules.config to look like:

    <rules>  
             <rule name="location_category">
              <match url="^([a-zA-Z0-9-+]+)$"/>
              <action type="Rewrite" url="search.aspx?category={R:1}"/>
            </rule>
        </rules>

    and in your post you have written the filename as rewritemaps.config, it should be rewriteRules.config or is it just a typo?

    Best regards
    Johan

    Tuesday, January 14, 2014 8:40 AM
  • User-1246604461 posted

    That was a typo, I changed it :)

    I changed my rewriteRules.config, but still get the error:

    500 - Internal server error.
    There is a problem with the resource you are looking for, and it cannot be displayed.

    I also restarted my application pool


    What am I missing?

    Tuesday, January 14, 2014 8:54 AM
  • User1508394307 posted

    Peter,

    Did you test if <rules> section works if you set it directly in the web.config?

    I think your matching rule is incorrect and must be

    <match url="^([a-zA-Z0-9\-\+]+)$"/>

    If this was tested then check if rewriteRules.config has correct permissions.

    P.S.

    valuja is right, the rewriteRules.config should have only <rules>...</rules>. 

    Tuesday, January 14, 2014 11:28 AM
  • User-1246604461 posted

    @smirnov

    yes, my rules do work when they are directly in my web.config

    My rewriteRules.config is in the same folder as my web.config (in the root of my website) and has the EXACT same permissions.

    The rewriteRules.config is larger than 250Kb though...could that be the problem? Because I see this here: http://ruslany.net/2010/05/storing-url-rewrite-mappings-in-a-separate-file/#comment-2043

    However, I don't see the key HKLM\SOFTWARE\Microsoft\InetStp\Configuration\MaxWebConfigFileSizeInKB (REG_DWORD) in my registry...

    Tuesday, January 14, 2014 2:03 PM
  • User1508394307 posted

    I believe you should get another error message because of size and size is not an issue here. Also rewriting works from web.config which should be bigger than 250Kb too.

    You can also easily check if rewriteRules.config with just one rule works

    <rules>
    <rule name="location_category">
    <match url="^([a-zA-Z0-9-+]+)$"/>
    <action type="Rewrite" url="search.aspx?category={R:1}"/>
    </rule>
    </rules>

    Did you try iisreset? What OS/IIS it is?

    P.S.

    If nothing helped, check what value you have (if you have access to registry)

    HKLM\Software\Microsoft\InetStp\Configuration\MaxWebConfigFileSizeInKB (for x32 system)
    HKLM\Software\Wow6432Node\Microsoft\InetStp\Configuration\MaxWebConfigFileSizeInKB (for x64 system)

    Tuesday, January 14, 2014 2:16 PM
  • User-1246604461 posted

    Rewriting works when I add parts of the total set of rules to the rewriteRules.config

    I'm sure all rules work, so I tested and it works as long as the file is 250Kb max, after that it throws the error (which indeed does NOT mention filesize).

    There is no Configuration section in my registry (I have 64bit).

    IIS 7.5.7600 on Windows 7

    Production server IIS Server 2008 R2 IIS 7.5.7600

    Any other way to fix this?

    Tuesday, January 14, 2014 2:40 PM
  • User1508394307 posted

    According to MSDN, the message regarding size must be "Cannot read configuration file because it exceeds the maximum file size"

    http://support.microsoft.com/kb/954864/en-us
    http://blogs.msdn.com/b/httpcontext/archive/2012/10/23/cannot-read-configuration-file-because-it-exceeds-the-maximum-file-size-web-config.aspx

    There are few topics on iis.net regarding same issue and they all suggest to create the key if it is not present 

    http://forums.iis.net/t/1155143.aspx?IIS+7+0+web+config+file+is+bigger+than+allowed

    I would suggest to follow Steve's suggestion

    Try adding it manually and do an iisreset.  

    PS: The normal backup your registry and be careful when messing with the registry.  If you are not comfortable, get someone who can assist with adding the key.

    Set size bigger than you have (as REG_DWORD value) and reset iis.

    P.S. 

    on my box that key does not exist too.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 14, 2014 3:08 PM