【问题标题】:IIS rewrite virtual folderIIS 重写虚拟文件夹
【发布时间】:2013-05-09 19:44:25
【问题描述】:

我需要在 IIS 中为以下内容创建 URL 重写规则:

发件人:

http://hostname/virtual_path_folder/myisapi.dll?a=1&b=1

收件人:

http://hostname/myisapi.dll?a=1&b=1

基本上,如果可能的话,我只想隐藏 virtual_path 文件夹。

【问题讨论】:

  • 这可能是可能的。您使用的是哪个 IIs 版本?
  • 您需要此规则仅在请求myisapi.dll?a=1&b=1 时应用?或者任何网址?
  • 任何 URL(如果可能)。谢谢

标签: url iis rewrite


【解决方案1】:

您可以遵循以下 2 条规则:

<rules>
    <rule name="Redirect if virtual_path_folder" stopProcessing="true">
        <match url="^virtual_path_folder/(.*)$" />
        <action type="Redirect" url="{R:1}" />
    </rule>
    <rule name="Rewrite to sub folder">
        <match url="^.*$" />
        <action type="Rewrite" url="virtual_path_folder/{R:0}" />
    </rule>
</rules>

第一个 Redirect if virtual_path_folder 将重定向每个以 virtual_path_folder/ 开头的请求。它将阻止任何人使用子文件夹访问您的内容。

第二个将任何请求(^.*$)重写到子文件夹:virtual_path_folder/{R:0}

【讨论】:

  • @cheesemacfly 我有一个类似的问题要解决。您的解决方案效果很好,但是如果我有一个不能应用规则的 virtual_path_folder_B 和 virtual_path_folder_C 怎么办?我尝试添加&lt;rule name="if_not_virtual_path_folder" stopProcessing="true"&gt; &lt;match url="^virtual_path_folder/(.*)$" negate="true" /&gt; &lt;action type="None" /&gt;,但没有成功!
  • @MaxS-Betclic 如果请求的 url 是 http://yourwebsite.com/virtual_path_folder_C,您想避免使用 Rewrite,而是显示 virtual_path_folder_C 的内容?
  • @cheesemacfly 是的,就是这样!
  • @MaxS-Betclic 为此,您可以将第二个规则模式 (&lt;match url="^.*$" /&gt;) 更改为:&lt;match url="^virtual_path_folder_C" negate="true" /&gt;。当 url 以 virtual_path_folder_C 开头时,它将阻止重写。它对你有用吗?
  • @cheesemacfly 感谢您的回复。其实我写了一个新的question,会比给cmets加东西方便!
猜你喜欢
  • 2020-08-19
  • 2012-11-22
  • 2011-01-20
  • 1970-01-01
  • 2012-08-21
  • 2020-02-23
  • 2017-08-27
  • 1970-01-01
  • 2023-04-08
相关资源
最近更新 更多