Redirect in IIS using Variables ($1$2)

让人想犯罪 __ 提交于 2019-12-13 02:33:26

问题


Right now I have a redirect set up like this

<rule name="EN" stopProcessing="true">
    <match url="en/(.*)" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
    <action type="Redirect" url="$1$2" />
</rule>

However, it is not working properly. I'm trying to get it to be so when a user types in www.mysite.com/en/anything.aspx That it redirects to www.mysite.com/anything.aspx

I have a feeling I've set something up wrong, maybe incorrect syntax.

Any help would be greatly appreciated!!


回答1:


Does your condition get a match so you know that part is OK? I dont think you use $1 $2 but {R:1} {R:2} etc.

<action type="Redirect" url="{R:1}" />

I have not tested this, but I would try this:

<rule name="EN" stopProcessing="true">
  <match url="en/(.*)" />
  <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  </conditions>
  <action type="Redirect" redirectType="Permanent" url="{R:1}" />    
</rule>


来源:https://stackoverflow.com/questions/8124987/redirect-in-iis-using-variables-12

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!