【问题标题】:Web config rewrite rule not displaying correct pageWeb 配置重写规则不显示正确的页面
【发布时间】:2016-01-11 14:17:48
【问题描述】:

我正在尝试重写 Mediawiki 站点中的 url,根据失败的请求日志文件输出,一切看起来都在工作。然而,正在显示的页面是原始页面,而不是重写中的 url。基本上我希望

www.website.com/State/City/Category

在

www.website.com/index.php?title=Special:RunQuery/CategoryPage&CategoryPage[State]= State&CategoryPage[City]=City&CategoryPage[Category]=Category&wpRunQuery=true 显示页面

相反,它似乎在

www.website.com/index.php?title=State/City/Category

显示页面 打印 _SERVER 将 QUERY_STRING 显示为 Special:RunQuery 页面,但其他所有变量都显示 index.php 或 /State/City/Category。我的 web.config 重写规则如下所示:

<rewrite>
    <rules>
        <rule name="Root Hit Redirect" stopProcessing="true">
            <match url="^$" />
            <action type="Rewrite" url="/index.php?title=Main_Page" />
        </rule>
       <rule name="RedirectUserFriendlyURL1" stopProcessing="true">
           <match url="^index\.php$" />
           <conditions>
               <add input="{REQUEST_METHOD}" pattern="^POST$" />
               <add input="{QUERY_STRING}" pattern="^title=([^=&amp;]+)$" />
           </conditions>
           <action type="Redirect" url="{C:1}" appendQueryString="false" />
       </rule>
       <rule name="RewriteUserFriendlyCategoryURL" stopProcessing="true">
            <match url="^([^/]+)/([^/]+)/([^/]+)/?$" />
            <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            </conditions>
            <action type="Rewrite" url="index.php?title=Special:RunQuery/CategoryPage&amp;CategoryPage[State]={UrlDecode:{R:1}}&amp;CategoryPage[City]={UrlDecode:{R:2}}&amp;CategoryPage[Category]={UrlDecode:{R:3}}&amp;wpRunQuery=true" />
        </rule>
       <rule name="RewriteUserFriendlyURL1" stopProcessing="true">
           <match url="^(.+)$" />
           <conditions>
               <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
               <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
           </conditions>
           <action type="Rewrite" url="index.php?title={UrlDecode:{R:1}}" />
       </rule>
    </rules>
</rewrite>

感谢任何帮助解决这个问题。已经绞尽脑汁2天了。谢谢!

【问题讨论】:

    标签: iis url-rewriting web-config iis-7.5 mediawiki


    【解决方案1】:

    我在本地尝试了您的规则,它们按照您的指示工作,请求: 测试:
    RequestURL="/State/City/Category"

    将正确地重写为: "localhost:80/index.php?title=Special:RunQuery/CategoryPage&CategoryPage[State]=State&CategoryPage[City]=City&CategoryPage[Category]=Category&wpRunQuery=true"

    我的建议是使用失败的请求跟踪:http://www.iis.net/learn/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules 这应该会告诉你到底发生了什么。

    【讨论】:

    • 感谢您检查它。我尝试了失败的请求跟踪,就像我上面所说的,一切看起来都很好。在日志的末尾,它执行了一个看起来不错的重写操作,规则评估显示了新的查询字符串,rewrite end 显示了 index.php 的请求 url,然后它向完整的正确字符串发出请求,然后以 200 结束成功。我想知道的是,Mediawiki 可能正在查看其他内容并根据其他变量提供不同的页面。 Request_URI 仍设置为 /State/City/Category。你能改变 web.config 中的 Request_URI 和其他 _Server 变量吗?
    【解决方案2】:

    好吧,我想既然 Carlos 说 web.config 看起来不错,它一定是 Mediawiki,果然我找到了一个地方,它检查并使用 $_SERVER['REQUEST_URI']。这可能会在 Apache 的 URL 重写上被更改,但它不在 IIS 中。幸运的是,我设法通过更改 LocalSettings.php 来修复它,因此无需对核心代码进行任何修改。因此,如果其他人对 IIS 和 Mediawiki,或 IIS 和任何其他以 PHP Apache 为中心的站点有此问题,您可以在下面添加此代码:

    $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME']."?".$_SERVER['QUERY_STRING'];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 2021-05-04
      • 2013-04-19
      • 1970-01-01
      • 2013-05-26
      相关资源
      最近更新 更多