简体   繁体   中英

iis rewrite keep path (keep everything but the file name)

attempting to re route

https://xxxxx.aaa.bb.cc.dd/FOB_Main.aspx?FOB=O to
https://xxxxx.aaa.bb.cc.dd/FOB_Main_Rewrite.aspx?FOB=O

and

https://xxxxx.aaa.bb.cc.dd/testdev/FOB_Main.aspx?FOB=O to
https://xxxxx.aaa.bb.cc.dd/testdev/FOB_Main_Rewrite.aspx?FOB=O

and

https://xxxxx.aaa.bb.cc.dd/net/prodmirror/FOB_Main.aspx?FOB=O to
https://xxxxx.aaa.bb.cc.dd/net/prodmirror/FOB_Main_Rewrite.aspx?FOB=O

so retain everything before an aspx page and the query string. and replace it with a new aspx page. (replace only the filename and keep everything else)

here is my attempt.

  <rule name="Fob_Main_decommisioned" stopProcessing="true">
    <match url="^fob_main.aspx" />
    <action type="Redirect" url="/FOB_Main_Rewrite.aspx" redirectType="Temporary" />
  </rule>

this is working fine for

https://xxxxx.aaa.bb.cc.dd/FOB_Main.aspx?FOB=O to
https://xxxxx.aaa.bb.cc.dd/FOB_Main_Rewrite.aspx?FOB=O

but it is changing.

https://xxxxx.aaa.bb.cc.dd/testdev/FOB_Main.aspx?FOB=O to
https://xxxxx.aaa.bb.cc.dd/FOB_Main_Rewrite.aspx?FOB=O

I also attempted

<rule name="Fob_Main_decommisioned" stopProcessing="true">
        <match url="^fob_main.aspx" />
        <action type="Redirect" url="{HTTP_HOST}/FOB_Main_Rewrite.aspx" redirectType="Temporary" />
      </rule>

but now I am getting

https://xxxxx.aaa.bb.cc.dd/testdev/xxxxx.aaa.bb.cc.dd/FOB_Main_Rewrite.aspx?FOB=O

I also attempted

<rule name="Fob_Main_decommisioned" stopProcessing="true">
    <match url="(^.*)fob_main.aspx" />
    <action type="Redirect" url="/{R:1}FOB_Main_Rewrite.aspx" redirectType="Temporary" />
  </rule> 

but I am back to

https://xxxxx.aaa.bb.cc.dd/FOB_Main_Rewrite.aspx?FOB=O

(it is removing the testdev again)

interestingly using this rule

 <rule name="Fob_Main_decommisioned" stopProcessing="true">
         <match url="(^.*)fob_main.aspx" />
        <action type="Redirect" url="/{R:1}FOB_Main_Rewrite.aspx" redirectType="Temporary" />

and directly typing into the browser

https://xxxxx.aaa.bb.cc.dd/testdev/testdev/FOB_Main.aspx?FOB=O

re routes me to the page I would like to go to.

https://xxxxx.aaa.bb.cc.dd/testdev/FOB_Main_Rewrite.aspx?FOB=O

This rule looks correct (if you placed this rule in root application):

<rule name="Fob_Main_decommisioned" stopProcessing="true">
   <match url="(^.*)fob_main.aspx" />
   <action type="Redirect" url="/{R:1}FOB_Main_Rewrite.aspx" redirectType="Temporary" />
</rule> 

This rule will work, if you placed it in sub application:

<rule name="Fob_Main_decommisioned" stopProcessing="true">
    <match url="^fob_main.aspx" />
    <action type="Redirect" url="FOB_Main_Rewrite.aspx" redirectType="Temporary" />
</rule>

Most probably you back to https://xxxxx.aaa.bb.cc.dd/FOB_Main_Rewrite.aspx?FOB=O , because browser cached your wrong redirect before. Can you please do this steps:

  1. Apply this rule
  2. Clear cache in your browser
  3. Try to open https://xxxxx.aaa.bb.cc.dd/testdev/FOB_Main.aspx?FOB=O

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