【问题标题】:IIS URL Rewrite Query StringIIS URL 重写查询字符串
【发布时间】:2017-07-18 22:32:40
【问题描述】:

我希望有人能够在自定义 URL 重写方面提供一些帮助。

我有一个 URL http://website/central/?agentcontent=about,我希望在 URL 栏中重写它看起来像 http://website/central/about 的 URL。

目前我的网络配置如下:

<rule name="Agency Sub Page">
  <match url="(.*)" />
      <conditions>
         <add input="{QUERY_STRING}" pattern="(.*)agentcontent=(.*)" />
       </conditions>
      <action type="Rewrite" url="{C:1}{C:2}" />
</rule>

但是什么也没发生,url 保持不变。

URL Rewrite 肯定已安装并可以正常工作,因为我有其他网站使用它,没有任何问题。

【问题讨论】:

  • 查看文档中“重写”和“重定向”之间的区别 - iis.net/learn/extensions/url-rewrite-module/…
  • 我确实已经阅读了该页面,但我很确定我不是在重定向之后我在重写之后。原始链接工作正常。我只希望它看起来“漂亮”。除非你说我完全不理解重写和重定向之间的区别。

标签: php iis url-rewriting


【解决方案1】:

您可以通过以下规则做到这一点:

<rule name="Agency Sub Page with trailing slash" stopProcessing="true">
  <match url="(.*)/$" />
      <conditions>
                    <add input="{QUERY_STRING}" pattern="agentcontent=(.*)" />
       </conditions>
      <action type="Rewrite" url="{R:0}{C:1}" appendQueryString="false" />
</rule>
<rule name="Agency Sub Page" stopProcessing="true">
  <match url=".*" />
      <conditions>
                    <add input="{QUERY_STRING}" pattern="agentcontent=(.*)" />
       </conditions>
      <action type="Rewrite" url="{R:0}/{C:1}" appendQueryString="false" />
</rule>

我使用了两条规则,因为末尾有斜杠(处理两个网址:http://website/central/?agentcontent=abouthttp://website/central?agentcontent=about)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-24
    • 1970-01-01
    相关资源
    最近更新 更多