如何将https://sitename.com重定向到https://www.sitename.com [英] How to redirect https://sitename.com to https://www.sitename.com
本文介绍了如何将https://sitename.com重定向到https://www.sitename.com的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在htaccess文件中的重定向成功将example.com重定向到 https://www.example.com
My redirect in htaccess file successfully redirects example.com to https://www.example.com
,但是如果我输入: https://example.com 在地址栏中,我没有被重定向。
but if I type: https://example.com in the address bar, I am not redirected.
当前代码看起来像这样:
Current code looks a bit like this:
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无效:
Adding the www after the https:// does not work:
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
推荐答案
这还将重定向 https://example.com
到 https:// www.example.com
您需要具有这样的规则。
This will also redirect https://example.com
to https://www.example.com
You need to have your rule like this.
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^ https://www.example.com%{REQUEST_URI} [L,R=301]
让我知道如何解决。
这篇关于如何将https://sitename.com重定向到https://www.sitename.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文