IIS 10 向 WordPress 应用发送请求的 URL 重写规则

问题描述 投票:0回答:1

我在 Windows Server 2019 上运行 IIS 10,上面安装了 WordPress(除其他外),并安装了 URL 重写 2.1。 IIS 已针对 Wordpress 应用程序正确配置,该应用程序本身运行良好。

我正在尝试从服务器的根目录定义 URL 重写规则,该规则将向 WordPress 应用程序发送某些请求。

如果我浏览到

https://this.is.my.server.com/wp/this-is-a-test/
,页面加载正常。

我定义了一个重写映射,其中包含一个将

/this-is-a-test
发送到
/wp/this-is-a-test/
的条目,并创建一个使用此映射重定向请求的重写规则,它工作正常 - 原始 URL 返回 301 HTTP 状态,并且请求得到转发到预期的 URL。规则如下:

<rule name="Rewrite rule1 for RewriteFriendlyUrlsToBlog" enabled="true" stopProcessing="true">
    <match url=".*" />
        <conditions>
            <add input="{RewriteFriendlyUrls:{REQUEST_URI}}" pattern="(.+)" />
        </conditions>
    <action type="Redirect" url="{C:1}" appendQueryString="true" logRewrittenUrl="true" />
</rule>

但是,我需要重写规则,而不是重定向。如果我将此规则编辑为重写,则会收到 404 错误。调整后的规则与之前的完全相同,只是重写而不是重定向:

<rule name="Rewrite rule1 for RewriteFriendlyUrlsToBlog" enabled="true" stopProcessing="false">
    <match url=".*" />
    <conditions>
        <add input="{RewriteFriendlyUrls:{REQUEST_URI}}" pattern="(.+)" />
    </conditions>
    <action type="Rewrite" url="{C:1}" appendQueryString="true" logRewrittenUrl="true" />
</rule>

详细错误信息包括:

Requested URL: https://this.is.my.server.com/wp/this-is-a-test/

...这向我暗示了两件事:

  1. 重写规则本身可以正确发送请求,但是
  2. 重写的请求可能缺少 PHP/WordPress 正确解释请求所需的信息,或者
  3. WordPress 文件夹中将非文件或文件夹的请求重定向到
    index.php
    的规则由于某种原因未执行。

但我不知道需要做什么才能使这个重写规则正常工作。

wordpress iis iis-10 url-rewrite-module
1个回答
0
投票

通过反复试验,我发现为了正确进行重写,我需要重写为

index.php
- 确保选中“附加查询字符串”选项 - 而不是预期的 URL。

这似乎有效:

<rule name="TEST single URL rewrite to PHP" enabled="false" patternSyntax="ECMAScript" stopProcessing="false">
    <match url="^this-is-a-test" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
    <action type="Rewrite" url="/wp/index.php" />
</rule>

也可以使用重写映射。

我认为,对于重写,无论您的“stopProcessing”选项设置为何,WordPress 文件夹中将既不是文件也不是文件夹的请求重写到index.php 的规则都不会被处理。

© www.soinside.com 2019 - 2024. All rights reserved.