自定义页面将非www的错误重定向到从microsoft azure开发的wordpress站点的www

问题描述:

I have added this code in web.config of my wordpress site:

<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>

This perfectly works for redirection like homepage, default wordpress url(login.php, wp-admin). Examples:

  1. If I go to link poudelmadhav.com it redirects to www.poudelmadhav.com
  2. If I go to link poudelmadhav.com/wp-login.php it redirects to www.poudelmadhav.com/wp-login.php

But this doesnot work in custom pages of wordpress that I have created after installing wordpress. For examples:

  1. If I want to go poudelmadhav.com/contact it redirects to www.poudelmadhav.com not www.poudelmadhav.com/contact
  2. If I want to go poudelmadhav.com/about-me it redirects to www.poudelmadhav.com not www.poudelmadhav.com/about-me

I have followed the instructions from here. How can I solve this please help me.

我已将此代码添加到我的wordpress网站的 web.config code>中: p >

 &lt; rule name =“Redirect to WWW site”&gt; 
&lt; match url =“。*”/&gt; 
&lt; conditions logicalGrouping =“MatchAny”&gt;  
&lt; add input =“{HTTP_HOST}”pattern =“^(www \。)(。*)$”negate =“true”/&gt; 
&lt; / conditions&gt; 
&lt; action type =“ 重定向“url =”http:// www。{HTTP_HOST} / {R:0}“redirectType =”Permanent“/&gt; 
&lt; / rule&gt; 
  code>  pre> 
 
 这完全适用于重定向,如主页,默认wordpress url(login.php,wp-admin)。 示例: p> 
 
 
  1. 如果我去链接poudelmadhav.com它会重定向到www.poudelmadhav.com li>
  2. 如果我去链接poudelmadhav。 com / wp-login.php它重定向到www.poudelmadhav.com/wp-login.php
nnn

但是这在我自己的wordpress自定义页面中不起作用 安装wordpress后创建。 例如: p>

  1. 如果我想去poudelmadhav.com/contact,它会重定向到www.poudelmadhav.com而不是www.poudelmadhav.com/contact li> \ n
  2. 如果我想去poudelmadhav.com/about-me它重定向到www.poudelmadhav.com而不是www.poudelmadhav.com/about-me
nnn >我已按照这里。 如何解决这个问题请帮帮我。 p> div>

I was able to reproduce your issue on my site. To fix this, you'll need to move the code you posted above before Rewrite to index.php rule in the web.config file as below. And don't forget to clear the web browser's cache when you test it.

<?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>