如何重定向https://sitename.com到https://www.sitename.com.



我在htaccess文件中的重定向成功地将example.com重定向到https://www.example.com

但是如果我键入:https://example.com在地址栏中,我没有被重定向。

当前代码看起来有点像这样:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^example.local$
RewriteCond %{SERVER_NAME} !.cms.me$ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

在https://之后添加www不起作用:

RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

这也会将https://example.com重定向到https://www.example.com您需要有这样的规则。

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^ https://www.example.com%{REQUEST_URI} [L,R=301]

让我知道结果如何。

最新更新