如何在我的Wordpress网站上将非www重定向到www

问题描述 投票:-1回答:2

我正在尝试将所有请求从https://mywebsite.com重定向到https://www.mywebsite.com(Wordpress网站)。

我激活了SSL,并使用“真正简单的SSL”插件启用了https。从http://www.mywebsite.com重定向到https://www.mywebsite.com效果很好。

但是当我编写不带www的网站时,它将无法正常工作。我试图将大量网站的代码添加到我的.htaccess中,以将非www重定向到www URL,但是它不起作用。我认为将所有试图使事情正常工作的.htaccess配置粘贴到这里是没有用的,但是什么也没有。请帮助我:(

wordpress ssl web https http-status-code-301
2个回答
0
投票

我认为您可以在Google上轻松找到答案,例如https://wordpress.org/support/topic/forcing-http-to-https-and-non-www-to-www/最后一篇文章告诉您该怎么做,将其添加到您的.htaccess文件中(在FTP站点根目录中的FTP上找到):

RewriteEngine on
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.example.com%{REQUEST_URI} [L,R=301]

((注意:请确保将www.example.com更改为您的域。)

而且,您确定对.htaccess所做的任何更改都改变了任何结果吗?一些托管公司要求您通过按下后端中的按钮将更改推送到.htaccess。否则更改.htaccess无效。

更新

好的,它在Windows服务器上运行与此处提及非常相关。.htaccess在Windows服务器上不起作用。

您可以尝试这里提到的吗?:IIS Redirect non-www to www AND http to https

因此,将其放在web.config中:(不要忘记用您的网站替换zzz.com

<rule name="Force WWW and SSL" enabled="true" stopProcessing="true">
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAny">
      <add input="{HTTP_HOST}" pattern="^[^www]" />
      <add input="{HTTPS}" pattern="off" />
  </conditions>
  <action type="Redirect" url="https://www.zzz.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>

0
投票

回复此更新:不起作用。也许我要等几个小时才能产生效果?也许我必须更改IIS设置中的某些内容?那是我的web.config文件。

        <?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <clear />
                <add value="index.php" />
            </files>
        </defaultDocument>
        <rewrite>
            <rules>
                <clear />
                <rule name="WordPress Rule" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" />
                </rule>
<rule name="Force WWW and SSL" enabled="true" stopProcessing="true">
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAny">
      <add input="{HTTP_HOST}" pattern="^[^www]" />
      <add input="{HTTPS}" pattern="off" />
  </conditions>
  <action type="Redirect" url="https://www.mywebsitename.it/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
            </rules>
            <outboundRules>
                <clear />
            </outboundRules>
        </rewrite>
    </system.webServer>
</configuration>
© www.soinside.com 2019 - 2024. All rights reserved.