htaccess文件重定向以强制执行https

时间:2017-08-12 21:00:46

标签: php .htaccess https

我正在尝试修改我的.htacess文件以强制执行https,但因为我已经有了一些规则,所以我似乎打破了它。有人可以帮忙建议我吗?

DirectoryIndex index.php
RewriteEngine on

RewriteCond $1 !^(index\.php|    (.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]

3 个答案:

答案 0 :(得分:1)

您可以尝试:

RewriteEngine on
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

您还可以查看此link。您可能需要许多其他规则。

答案 1 :(得分:0)

我这样做:

RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

答案 2 :(得分:0)

使用RewriteEngine。这将迫使ssl。

RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]