[英]htaccess Redirect All Traffic to https
I'm a beginner when it comes to doing stuff with htaccess so please be patient with my dumb question. 在使用htaccess进行操作时,我是一个初学者,因此请耐心等待我的愚蠢问题。 I know that this has been addressed a lot ( here , here , and here for example) but it doesn't seem to work for my situation. 我知道这个问题已经解决了很多(例如此处 , 此处和此处 ),但似乎不适用于我的情况。 My browser displays a "redirect loop" error with this code in my htaccess file: 我的浏览器在我的htaccess文件中显示以下代码的“重定向循环”错误:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Trying to redirect to https
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</IfModule>
I know that this probably has something to do with the RewriteCond
and the RewriteRule
before I redirect to https, but I don't really know what I'm doing here and I don't know what to change. 我知道在重定向到https之前,这可能与RewriteCond
和RewriteRule
,但是我真的不知道我在这里做什么,也不知道要更改什么。
Update: 更新:
Some more info that might be helpful: 一些可能有用的更多信息:
https://my.site.com
it loads just fine. 当我删除“重定向到https”代码并手动键入https://my.site.com
它加载就好了。 The app that I'm trying to redirect resides in a subfolder of another app which also has an .htaccess file. 我要重定向的应用程序驻留在另一个也有.htaccess文件的应用程序的子文件夹中。 Here's the code for that app: 这是该应用程序的代码:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] RewriteEngine On </IfModule>
This is what firebug says: 这是萤火虫说的:
Change order of your rules and keep 301 rules before other internal rewrite rule: 更改规则的顺序,并在其他内部重写规则之前保留301条规则:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Trying to redirect to https
RewriteCond %{HTTPS} off
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.