![](/img/trans.png)
[英]How to redirect all my website posts/pages from Http (+ www or non-www) to Https (non-www) URL
[英]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).
我激活了 SSL 并使用“Really Simple SSL”插件来启用 https。 从http://www.mywebsite.com重定向到https://www.mywebsite.Z4D2366D9A2FEDA4BEC505C
但是当我写没有www的网站时,它就不起作用了。 我试图在我的 .htaccess 中添加大量来自大量网站的代码,以将非 www 重定向到 www URL 但它不起作用。 我认为在这里粘贴所有 .htaccess 配置是没有用的,我试图让事情正常工作但没有。 请帮我:(
我想你可以很容易地在谷歌上找到答案,比如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]
(注意:确保将 www.example.com 更改为您的域。)
此外,您确定您对 .htaccess 所做的任何更改都改变了任何结果吗? 一些托管公司要求您通过按下后端的按钮将更改推送到 .htaccess。 否则对 .htaccess 的更改无效。
更新
好的,它在 Windows 服务器上运行与这里提到的非常相关。 .htaccess 在 Windows 服务器上不起作用。
你能试试这里提到的吗?: IIS 将非 www 重定向到 www 和 http 到 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>
回复更新:不行。 也许我必须等待几个小时才能产生效果? 也许我必须更改 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.