我的.htaccess文件是
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteCond %{REQUEST_URI} ^/(cust1|cust2|cust3)
RewriteRule (.*) /mysitecustomer/$1 [R=301,L]
我想将所有HTTP重定向到HTTPS,所以我按照this链接修改了.htaccess。
不起作用:http不会重定向到https,而是保留在http上。例如,当我转到站点http://www.mywebsite.com时,它保留在http://并显示“不安全”。我需要它重定向到https,以便“不安全”消失。
新的.htaccess
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteCond %{REQUEST_URI} ^/(rb|LakmeLever|Itc)
RewriteRule (.*) /mysitecustomer/$1 [R=301,L]
#http to https redirect
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mywebsite\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]
#
但是http仍未重定向到https
编辑1(尝试不起作用)
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteCond %{REQUEST_URI} ^/(rb|LakmeLever|Itc)
RewriteRule (.*) /mysitecustomer/$1 [R=301,L]
#Siddharth http to https redirect
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.mywebsite.com [R=301,L]
编辑2(尝试不起作用)
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteCond %{REQUEST_URI} ^/(rb|LakmeLever|Itc)
RewriteRule (.*) /mysitecustomer/$1 [R=301,L]
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
编辑3(尝试,不起作用)
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteCond %{REQUEST_URI} ^/(rb|LakmeLever|Itc)
RewriteRule (.*) /mysitecustomer/$1 [R=301,L]
RewriteEngine Off
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
编辑4(尝试不起作用)
RewriteEngine On
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
答案 0 :(得分:0)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
我在我的网站中使用了此代码,并且工作正常。 请尝试这个。