简体   繁体   中英

IIS URL Rewrite part of filename as folder

I would like to use part of the filename as a folder name, my redirect is working but the rewrite does not work, this is my web.config (also has a rule to remove the file extension):

Original: https://www.ipressnet.com.br/v6/client_tracking.aspx?id=x

Rewrite: https://www.ipressnet.com.br/v6/client/tracking?id=x

THIS WORKS:

<rule name="RemoveASPx" enabled="true" stopProcessing="false">
  <match url="(.*)\.aspx" />
  <action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>

<rule name="AddASPx" enabled="true">
  <match url=".*" negate="false" />
  <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    <add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
  </conditions>
  <action type="Rewrite" url="{R:0}.aspx" />
</rule>

THIS DOES NOT WORK:

<rule name="RemoveClient" enabled="true" stopProcessing="false">
  <match url="^v6/?$|^client_(.*)$" />
  <action type="Redirect" url="client/{R:1}" />
</rule>

<rule name="AddClient" enabled="true">
  <match url="^v6/client/(.*)$" negate="false" />
  <action type="Rewrite" url="v6/client_{R:1}.aspx" />
</rule>

I appreciate any help, thank you!

You can write RemoveASPx and RemoveClient in the same rule.
The following rule maybe achieve your requirement.

<rule name="rewrite rule" enabled="true" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{URL}" pattern="^/v6(.*)client_(.*)\.aspx$" />
                </conditions>
                <action type="Redirect" url="v6{C:1}client/{C:2}" redirectType="Temporary" />
            </rule>
            <rule name="(.*)" enabled="false">
                <match url="(.*)" />
                <conditions>
                    <add input="{URL}" pattern="^/v6/client/(.*)" />
                </conditions>
                <action type="Rewrite" url="v6/client_{C:1}.aspx" />
            </rule>

<rule name="r1" stopProcessing="true">
   <match url="v6/(client)?(_)?(.*).aspx" ignoreCase="false" />
    <action type="Rewrite" url="v6/{R:1}/{R:3}" />
</rule>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM