[英]How to redirect non-www to www on my Wordpress website
I'm trying to redirect all the requests from https://mywebsite.com to https://www.mywebsite.com (Wordpress Website). I'm trying to redirect all the requests from https://mywebsite.com to https://www.mywebsite.com (Wordpress Website).
I activated SSL and used the "Really Simple SSL" plugin to enable https.我激活了 SSL 并使用“Really Simple SSL”插件来启用 https。 Redirect from http://www.mywebsite.com to https://www.mywebsite.com works nice.
从http://www.mywebsite.com重定向到https://www.mywebsite.Z4D2366D9A2FEDA4BEC505C
But when I write the website without www, it doesn't work.但是当我写没有www的网站时,它就不起作用了。 I tried to add to my .htaccess lots of code from tons of website to redirect non-www to www URL but it doesn't work.
我试图在我的 .htaccess 中添加大量来自大量网站的代码,以将非 www 重定向到 www URL 但它不起作用。 I think is unuseful to paste here all the .htaccess configuration I tried to make things work but nothing.
我认为在这里粘贴所有 .htaccess 配置是没有用的,我试图让事情正常工作但没有。 Please help me:(
请帮我:(
I think you can find answers on google easily, like https://wordpress.org/support/topic/forcing-http-to-https-and-non-www-to-www/ The last post tells you what to do, add this to top of your .htaccess (found on FTP in root of your Wordpress site):我想你可以很容易地在谷歌上找到答案,比如https://wordpress.org/support/topic/forcing-http-to-https-and-non-www-to-www/最后一篇文章告诉你该怎么做,将此添加到 .htaccess 的顶部(在 Wordpress 站点的根目录中的 FTP 上找到):
RewriteEngine on
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.example.com%{REQUEST_URI} [L,R=301]
(NOTE: Make sure you change www.example.com to your domain.) (注意:确保将 www.example.com 更改为您的域。)
Also, are you certain any of the changes you made to .htaccess have changed any outcomes?此外,您确定您对 .htaccess 所做的任何更改都改变了任何结果吗? Some hosting companies require you to push changes to .htaccess by pressing a button in the backend.
一些托管公司要求您通过按下后端的按钮将更改推送到 .htaccess。 Or else changes to the .htaccess have no effect.
否则对 .htaccess 的更改无效。
Update更新
Ok, that it is running on Windows server is very relevant to mention here.好的,它在 Windows 服务器上运行与这里提到的非常相关。 .htaccess does not work on Windows server.
.htaccess 在 Windows 服务器上不起作用。
Can you try what is mentioned here?: IIS Redirect non-www to www AND http to https你能试试这里提到的吗?: IIS 将非 www 重定向到 www 和 http 到 https
So put this in web.config
: (dont forget to replace zzz.com
with your website)所以把它放在
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>
Reply to the update: It doesn't work.回复更新:不行。 Maybe i have to wait hours to have effects?
也许我必须等待几个小时才能产生效果? Maybe i have to change something in IIS settings?
也许我必须更改 IIS 设置中的某些内容? That's my web.config file.
那是我的 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.