0

我想将我的域从 http 重定向到 https:

http://www.domain.com --> https://www.domain.com

可能吗?我一直在互联网上搜索,但我只发现:

http://domain.com --> https://www.domain.com

问题是,人们直接访问 http://www.domain.com怎么样?他们不是使用非 https 网址提供服务吗?反之亦然。我只想要从 HTTP 到 HTTPS 的简单重定向。可能吗?

谢谢

4

4 回答 4

2

I just want a simple redirection from the HTTP to HTTPS

试试这个简单的规则作为 .htaccess 的第一条规则

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
于 2013-10-24T10:27:59.347 回答
1

使用以下代码强制使用 www 和 SSL:

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
于 2013-10-24T10:12:58.220 回答
1

它适用于所有版本的 php,并将强制 SSL 和 www 访问所有裸域和链接:

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
  • 我们确实需要NE
  • 万维网。在第 4 行是可选的
  • “关闭”是必需的。
于 2014-03-09T13:30:41.890 回答
1

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteCond %{HTTPS} off

# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.

RewriteCond %{HTTP_HOST} ^tatwerat\.com [NC]

RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}

</IfModule>

于 2015-07-05T14:11:35.247 回答