【问题标题】:URL Rewrite not working with particular suffixURL 重写不适用于特定后缀
【发布时间】:2013-09-27 01:32:05
【问题描述】:

我正在将我的博客从 LAMP/PHP 迁移到 IIS。为了保留 URL,我使用了 URL 重写模块。在 192 页中,这适用于 191。基本上我需要用目录名称替换 URL 的“index.php”部分并附加一个“.html”后缀。

我的正则表达式模式:

^myblog/index\.php/(.+)

我的重写网址:

myblog/contents/{R:1}.html

这在大多数情况下都有效,重写

http://www.MYSITE/myblog/index.php/2013/04/29/goto_slides

http://www.MYSITE/myblog/contents/2013/04/29/goto_slides.html

但是,在一种情况下它会失败:

http://www.MYSITE/myblog/index.php/2013/04/29/goto_notes_evolving_java

这会返回 404,错误页面显示请求的 URL 是:

http://MYSITE:80/myblog/contents/2013/04/29/goto_notes_evolving_java

(请注意,没有添加“.html”后缀;添加后会找到该页面。)

我能看到的唯一的区别是有效的网址和不有效的网址是尾随的“java”。

我该如何解决或解决这个问题?


web.config,每个请求:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <directoryBrowse enabled="false" />
        <rewrite>
            <rules>
                <clear />
                <rule name="Rewrite blog URL from old PHP location" stopProcessing="true">
                    <match url="^myblog/index\.php/(.+)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="myblog/contents/{R:1}.html" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

【问题讨论】:

  • 您能否发布您正在使用的确切规则(如果有多个规则)(从 web.config 复制/粘贴)?您的代码中是否有任何重定向/重写?我看不出第二个网址会失败的任何原因......
  • @cheesemacfly 完成。而且没有代码 - 这些是非常基本的 HTML/CSS 页面,没有重定向、JavaScript 等。
  • 我真的不明白这个问题是从哪里来的。您可以尝试删除&lt;conditions&gt; 吗?它不应该改变任何东西,但这里没有使用所以......你可以运行Failed Request Tracing tool并将结果发布到互联网上的某个地方,看看是否有任何异常(如果你可以记录2个请求:一个工作和一个没有)?
  • @cheesemacfly “此网站未启用失败的请求跟踪” - 我无权更改它(商业托管)。
  • @cheesemacfly 删除条件已修复! 谢谢!将其发布为答案,我会接受。

标签: iis iis-7 url-rewriting


【解决方案1】:

删除条件将解决您的问题。
您的规则将变为:

<rule name="Rewrite blog URL from old PHP location" stopProcessing="true">
    <match url="^myblog/index\.php/(.+)" />
    <action type="Rewrite" url="myblog/contents/{R:1}.html" appendQueryString="true" />
</rule>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-27
    • 2015-12-30
    • 2013-09-23
    • 2016-01-02
    • 1970-01-01
    • 2012-10-05
    • 1970-01-01
    • 2012-12-01
    相关资源
    最近更新 更多