简体   繁体   English

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

[英]htaccess file to redirect to enforce https

I am trying to modify my .htacess file to enforce https, but because I already have some rules, I just appear to be breaking it. 我正在尝试修改.htacess文件以强制执行https,但是由于我已经有一些规则,因此我似乎正在打破它。 Can anyone help advise me? 谁能帮助我吗?

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]

You can try: 你可以试试:

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

You can also check this link out. 您也可以检查此链接 You have a lot of other rules you might need. 您可能还需要其他许多规则。

I do this: 我这样做:

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

Use the RewriteEngine. 使用RewriteEngine。 This will force ssl. 这将强制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]

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

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