locked
Subdomain URL Rewrite and ScriptResource.axd RRS feed

  • Question

  • User-1827850622 posted

     Hello,

     Below is my URL Rewrite:

    <rule name="SubDomain" stopProcessing="false">
         <match url="(.*)" />
         <conditions>
              <add input="{HTTP_HOST}" pattern="^(?!www)(\w+)\.domain\.com$" />
         </conditions>
         <action type="Rewrite" url="{C:1}/{R:1}" />
    </rule>

     So that will basically take x.domain.com and rewrite it as domain.com/x.

    The problem is that on the default.aspx page inside the folder "x", I am using Ajax so it adds /ScriptResource.axd?d=. The problem with this is that the browser looks for ScriptResource.axd in x.domain.com/ScriptResource.axd which will then be rewritten as domain.com/x/ScriptResource.axd.

    How would I go about fixing this?

    Saturday, April 24, 2010 5:30 AM

Answers

  • User744767459 posted

    Hi,

    With above rule, the second condition will be matched first. Hence, the back reference is not valid. Could you please move the second condition up, then test again? The rule looks like this:

    <rule name="SubDomain" stopProcessing="false">
         <match url="(.*)" />
         <conditions>
    <add input="{URL}" negate="true" pattern="\.axd$" />
              <add input="{HTTP_HOST}" pattern="^(?!www)(\w+)\.domain\.com$" />
         </conditions>
         <action type="Rewrite" url="{C:1}/{R:1}" />
    </rule>

    Thanks.

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Monday, April 26, 2010 12:12 AM

All replies

  • User973888104 posted

    Hi ,

    Not sure of this will do what you need but tip 10 in the following link has a rule to bypass processing of .axd's.  

    http://blogs.iis.net/ruslany/archive/2009/04/08/10-url-rewriting-tips-and-tricks.aspx

    Thanks

    Richard

    Sunday, April 25, 2010 10:07 PM
  • User-1827850622 posted

     For some reason I could not make that work. I did however, manage to rewrite x.domain.com/ScriptResource.axd and x.domain.com/WebResource.axd back to domain.com/ScriptResource.axd and domain.com/WebResource.axd with the following URL rewrite:

    <rule name="ScriptResource Rewrite" enabled="true" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                            <add input="{HTTP_HOST}" pattern="^(?!www)\w+\.domain\.com$" />
                            <add input="{URL}" pattern="^(/ScriptResource\.axd)$" />
                        </conditions>
                        <action type="Rewrite" url="{C:1}" />
                        <serverVariables>
                        </serverVariables>
                    </rule>
                    <rule name="WebResource Rewrite" enabled="true" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="^(?!www)\w+\.domain\.com$" />
                            <add input="{URL}" pattern="^(/WebResource\.axd)$" />
                        </conditions>
                        <action type="Rewrite" url="{C:1}" />
                    </rule>

    Sunday, April 25, 2010 10:45 PM
  • User744767459 posted

    Hi,

    If the stopProcessing enabled, the rewritten URLs won't be rewrite back. As Richard mentioned, we can by bypass processing of .axd's in one rule.

    <rule name="SubDomain" stopProcessing="false">
         <match url="(.*)" />
         <conditions>
              <add input="{HTTP_HOST}" pattern="^(?!www)(\w+)\.domain\.com$" />

    <add input="{URL}" negate="true" pattern="\.axd$" />

         </conditions>
         <action type="Rewrite" url="{C:1}/{R:1}" />
    </rule>

    If your problem persists, please update here. Thanks.

    Sunday, April 25, 2010 10:59 PM
  • User-1827850622 posted

     I put exactly what you wrote, now I get a 500 - Internal Server Error Message

    Sunday, April 25, 2010 11:25 PM
  • User744767459 posted

    Hi,

    Sorry, my mistake! It seems the back reference is not valid. Could you please post configuration sections in  your web.config here?

    Sunday, April 25, 2010 11:37 PM
  • User744767459 posted

    Hi,

    With above rule, the second condition will be matched first. Hence, the back reference is not valid. Could you please move the second condition up, then test again? The rule looks like this:

    <rule name="SubDomain" stopProcessing="false">
         <match url="(.*)" />
         <conditions>
    <add input="{URL}" negate="true" pattern="\.axd$" />
              <add input="{HTTP_HOST}" pattern="^(?!www)(\w+)\.domain\.com$" />
         </conditions>
         <action type="Rewrite" url="{C:1}/{R:1}" />
    </rule>

    Thanks.

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Monday, April 26, 2010 12:12 AM
  • User-1827850622 posted

     Thanks so much. Putting <add input="{URL}" negate="true" pattern="\.axd$" /> above <add input="{HTTP_HOST}" pattern="^(?!www)(\w+)\.domain\.com$" /> makes it work.

    Monday, April 26, 2010 12:17 AM