【问题标题】:web.config rewrite rule: rewriting from one query string to another which contains the firstweb.config 重写规则:从一个查询字符串重写到另一个包含第一个查询字符串
【发布时间】:2013-04-29 08:46:38
【问题描述】:

我有一个问题如下:

我想从 /index.php?jobs 重写为 /index.php?retail-jobs-in-london

我尝试了以下规则:

<rule name="jobs" stopProcessing="true">
   <match url="index.php$" />
   <conditions trackAllCaptures="true">
      <add input="{QUERY_STRING}" pattern="jobs" />
   </conditions>
   <action type="Redirect" appendQueryString="false" url="http://www.domain.com/index.php?retail-jobs-in-london" />
</rule>

但是,我在预期页面 /index.php?retail-jobs-in-london 收到错误,我相信因为“jobs”在预期页面的查询字符串中,所以它会尝试循环。

我怎样才能明确地查找完全是并且只有“jobs”的查询字符串?

提前致谢

【问题讨论】:

    标签: url-rewriting query-string


    【解决方案1】:

    这应该可行。

    更改此行,使正则表达式匹配字符串的开头和结尾:

    &lt;add input="{QUERY_STRING}" pattern="^jobs$" /&gt;

    或者您可以将其更改为仅当它以“作业”开头时才匹配,这将在其他内容添加到末尾时处理:

    &lt;add input="{QUERY_STRING}" pattern="^jobs" /&gt;

    【讨论】:

    • 非常感谢您的快速回答——这正是我所需要的。太快了,我还不能接受你的回答!
    猜你喜欢
    • 2015-08-05
    • 1970-01-01
    • 2011-12-11
    • 2017-09-19
    • 2015-09-17
    • 2014-12-03
    • 2018-02-08
    • 1970-01-01
    • 2016-08-13
    相关资源
    最近更新 更多