Swapnali Hadawale
Swapnali Hadawale

Reputation: 341

Rewrite rule to redirect URL

I am creating URL as - http://localhost:13490/level1/XYZ/hulhbgma79
trying to redirect this url on - http://localhost:13490/level1/PQR/HttpHandler.ashx?Id=hulhbgma79

In above given example of URL

  1. level1 - this name is changing according to condition, level2 or level3.
  2. XYZ - is virtual module.
  3. PQR is a folder in which HttpHandler.ashx is kept.
  4. Id is querystring parameter veriable.
  5. hulhbgma79 is value passed for querystring parameter.

I have written rule for this condition as bellow -

<rule name="RewriteURL" stopProcessing="true">
        <match url="^XYZ\/((([A-Za-z0-9]+)(\s|&amp;)([^\/]+))|(([^\/]+)(\s|&amp;))|([^\/]+))\/?$" />
          <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Redirect" url="{R:1}/PQR/HttpHandler.ashx?Id={R:9}" />

        </rule>

not working as expected.

Can any one kindly help me to get the solution for the same?

Upvotes: 3

Views: 229

Answers (1)

Amin Mozhgani
Amin Mozhgani

Reputation: 604

<rule name="RewriteURL" stopProcessing="true">
        <match url="(level\d)\/XYZ\/((([A-Za-z0-9]+)(\s|&amp;)([^\/]+))|(([^\/]+)(\s|&amp;))|([^\/]+))\/?$" />
          <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Redirect" url="{R:1}/PQR/HttpHandler.ashx?Id={R:2}" />

        </rule>

Upvotes: 1

Related Questions