.htaccess将root和index.php重定向到https root

时间:2016-12-16 19:01:53

标签: php .htaccess

请帮忙

如何将HTTP root和index.php重定向到HTTPS root。 样式和脚本与index.php相同。

RewriteEngine On

RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

谢谢!

1 个答案:

答案 0 :(得分:0)

一种方法可能是:

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.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%.   {REQUEST_URI} [L,R=301]