自定义页面将非 www 的错误重定向到 wordpress 站点的 www 开发自 microsoft azure
Custom pages redirect error of non www to www of wordpress site developed from microsoft azure
我在我的 wordpress 网站的 web.config
中添加了这段代码:
<rule name="Redirect to WWW site">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" redirectType="Permanent" />
</rule>
这非常适合重定向,例如主页、默认 wordpress url(login.php、wp-admin)。示例:
- 如果我去 link poudelmadhav.com 它会重定向到 www.poudelmadhav.com
- 如果我去 link poudelmadhav.com/wp-login.php 它重定向到 www.poudelmadhav.com/wp-login.php
但这不适用于我在安装 wordpress 后创建的 wordpress 自定义页面。例如:
- 如果我想去 poudelmadhav.com/contact 它会重定向到 www.poudelmadhav.com 而不是 www.poudelmadhav.com/contact
- 如果我想去 poudelmadhav.com/about-me 它会重定向到 www.poudelmadhav.com 而不是 www.poudelmadhav.com/about-me
我已按照 here. 的说明进行操作
我该如何解决这个问题,请帮助我。
我能够在我的站点上重现您的问题。要解决此问题,您需要将上面发布的代码移动到 web.config
文件中的 Rewrite to index.php
规则之前,如下所示。测试时不要忘记清除网络浏览器的缓存。
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to WWW site">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" redirectType="Permanent" />
</rule>
<rule name="Rewrite to index.php" patternSyntax="Wildcard">
<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" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
我在我的 wordpress 网站的 web.config
中添加了这段代码:
<rule name="Redirect to WWW site">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" redirectType="Permanent" />
</rule>
这非常适合重定向,例如主页、默认 wordpress url(login.php、wp-admin)。示例:
- 如果我去 link poudelmadhav.com 它会重定向到 www.poudelmadhav.com
- 如果我去 link poudelmadhav.com/wp-login.php 它重定向到 www.poudelmadhav.com/wp-login.php
但这不适用于我在安装 wordpress 后创建的 wordpress 自定义页面。例如:
- 如果我想去 poudelmadhav.com/contact 它会重定向到 www.poudelmadhav.com 而不是 www.poudelmadhav.com/contact
- 如果我想去 poudelmadhav.com/about-me 它会重定向到 www.poudelmadhav.com 而不是 www.poudelmadhav.com/about-me
我已按照 here. 的说明进行操作 我该如何解决这个问题,请帮助我。
我能够在我的站点上重现您的问题。要解决此问题,您需要将上面发布的代码移动到 web.config
文件中的 Rewrite to index.php
规则之前,如下所示。测试时不要忘记清除网络浏览器的缓存。
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to WWW site">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" redirectType="Permanent" />
</rule>
<rule name="Rewrite to index.php" patternSyntax="Wildcard">
<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" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>