[英]Redirect 301 from http to https doesn't work
I've this .htaccess in my share web hosting. 我的共享虚拟主机中有这个.htaccess。
RewriteOptions inherit
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
RedirectMatch 301 ^/directory(.*)$ https://www.example.com/$1
RedirectMatch 301 ^/directory/(.*)$ https://www.example.com/$1
RedirectMatch 301 ^/directory\-2014\.03\.04(.*)$ https://www.example.com/$1
RedirectMatch 301 ^/directory\-2014\.03\.04/(.*)$ https://www.example.com/$1
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "https\:\/\/www\.example\.com\/" [R=301,L]
I want all calls to http://www.example.com or http://example.com that redirect to https://www.example.com . 我希望所有对http://www.example.com或http://example.com的调用都重定向到https://www.example.com 。 But with my setup does not work either.
但是用我的设置也不起作用。
Try replacing: 尝试更换:
RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^/?$ "https\:\/\/www\.domain\.com\/" [R=301,L]
with 与
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTPS} =off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]
The above will first change http://domain.com
to http://www.domain.com
then it will redirect http://www.domain.com
to https://www.domain.com
if it isn't https://
上面的代码首先将
http://domain.com
更改为http://www.domain.com
然后将http://www.domain.com
重定向到https://www.domain.com
如果不是) https://
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.