I'm having a problem trying to get a wildcard url rewrite to handle anything besides the default.aspx page

Wally McClure 1 Reputation point
2024-05-08T19:59:06.9266667+00:00

I'm trying to do an url rewrite in an old asp.net webforms app. I'm using the iis url rewrite module from msft. I'm not experienced with the url rewrite module. I've tried a few things, but had no success. I have the following rule in a web.config in a folder. Everything at the folder level works fine, so servername.com/cmsvd/page.aspx redirects just fine. However, when I have servername.com/cmsvd/reports/reportfile.aspx, that one does not redirect. I assume it is something on my end. I'm guessing it has to do with the {R:1}, but I don't know that. any suggestions on how to also get /cmsvd/reports/reportfile.aspx to redirect as well? My rule is listed below. I can't hard code the number of folders in this, so I need it to work with everything below the /cmsvd folder. fyi, servername.com and newservername.com are the same machine and same folder, I need the url to be rewritten and not get into an infinite loop.

TIA.

<rewrite>
<rules>
<rule name="CanonicalHostNameRule" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^(.*)servername.com" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^servername.com$" />
          </conditions>
          <action type="Redirect" url=https://newservername.com/CMSVD/{R:1} />
        </rule>
</rules>
</rewrite>
Internet Information Services
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. hossein jalilian 8,080 Reputation points
    2024-05-08T21:32:08.2633333+00:00

    Thanks for posting your question in the Microsoft Q&A forum.

    Here's a revised version of your rule that should capture all URLs under the /cmsvd folder and redirect them to the new server:

    <rewrite>
        <rules>
            <rule name="RedirectToNewServer" stopProcessing="true">
                <match url="^cmsvd/(.*)" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^servername\.com$" />
                </conditions>
                <action type="Redirect" url="https://newservername.com/CMSVD/{R:1}" />
            </rule>
        </rules>
    </rewrite>
    
    

    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful

    0 comments No comments

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.