【问题标题】:URL Rewrite query in home directory iis主目录 iis 中的 URL 重写查询
【发布时间】:2013-02-25 19:56:21
【问题描述】:

我正在尝试重写 iis7 url 以处理主目录中的查询。最终目标是让它将index.php 附加到查询字符串的开头。我尝试的一切都以 500 错误结束。我做错了什么?

<rule name="post preview fix" patternSyntax="ECMAScript">
    <match url="^\?p=([0-9]+)&preview=true"  />
    <action type="Rewrite" url="index.php?p={R:1}&preview=true"  />
</rule>

【问题讨论】:

    标签: iis iis-7 url-rewriting web-config rewrite


    【解决方案1】:

    由于您希望将规则基于查询字符串,因此您必须使用条件。
    应该这样做:

    <rule name="post preview fix" stopProcessing="true">
        <match url="^index.php$" negate="true" />
        <conditions>
            <add input="{QUERY_STRING}" pattern="^p=([0-9]+)&preview=true" />
        </conditions>
        <action type="Rewrite" url="index.php" />
    </rule>
    

    如果请求的页面不是index.php,并且查询字符串匹配^p=([0-9]+)&amp;preview=true,则触发rwrite。
    appendQueryString 选项默认设置为 true,因此无需设置。

    【讨论】:

    • 如果您将&lt;action type="Rewrite" url="index.php" /&gt; 替换为&lt;action type="Redirect" url="index.php" redirectType="Temporary" /&gt;,您的浏览器中有想要的网址吗?如果是,那么问题来自您的index.php 文件。
    • 问题不是来自重定向/重写!
    • 这个网站的首页是一个虚拟目录,大概就是这个样子。在重写之前预览实际上工作得很好,所以我想也许为预览查询编写一个规则可以解决它。我是s.o.l吗?
    • 您是说调用http://website.com/index.php?p=1234&amp;preview=true 有效,但是当您从http://website.com/?p=1234&amp;preview=true 重定向到http://website.com/index.php?p=1234&amp;preview=true 时却无效?
    • 没有。只有主目录有一个重写规则:&lt;match url="^/?$" /&gt;&lt;action type="Rewrite" url="folder/index.html" /&gt;。原因是,大部分主页都是用 ASP 编写的,所以我们需要一种方法来用 PHP 实现部分网站,直到我们能够重新编写整个网站。当我删除此规则时,发布预览会完美运行。
    猜你喜欢
    • 1970-01-01
    • 2020-09-04
    • 1970-01-01
    • 2019-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-25
    相关资源
    最近更新 更多