繁体   English   中英

使用htaccess ..所有网址都必须重定向到带有www的https

[英]With htaccess .. all url must be redirect to https with www

domain.com
www.domain.com/xyz
http://domain.com/xyz
http://www.domain.com/xyz
https://domain.com/xyz

必须使用.htaccess重定向到下面(Apache 2.4)

https://www.domain.com/xyz

将此规则放在您的DOCUMENT_ROOT/.htaccess文件中:

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [R=302,L,NE]

编辑:使用curl命令行进行测试:

$> curl -I -k -A "Chrome" -L 'https://domain.com/'
HTTP/1.1 302 Found
Date: Wed, 25 Jun 2014 06:50:57 GMT
Server: Apache/2.4.7 (Ubuntu)
Location: https://www.domain.com/
Content-Type: text/html; charset=iso-8859-1

HTTP/1.1 200 OK
Date: Wed, 25 Jun 2014 06:51:00 GMT
Server: Apache/2.4.7 (Ubuntu)
Last-Modified: Thu, 19 Jun 2014 13:16:20 GMT
ETag: "7ac-4fc302ecafc5e"
Accept-Ranges: bytes
Content-Length: 1964
Vary: Accept-Encoding
Content-Type: text/html

尝试将其放在DOCUMENT_ROOT.htaccess文件中:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^/?(?:xyz/?)?$ https://www.domain.com/xyz [R=302,L]

如果可行,则可以将R=302更改为R=301

让我知道这是否适合您。 :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM