[英]htaccess Redirect All Traffic to https
在使用htaccess进行操作时,我是一个初学者,因此请耐心等待我的愚蠢问题。 我知道这个问题已经解决了很多(例如此处 , 此处和此处 ),但似乎不适用于我的情况。 我的浏览器在我的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>
我知道在重定向到https之前,这可能与RewriteCond
和RewriteRule
,但是我真的不知道我在这里做什么,也不知道要更改什么。
更新:
一些可能有用的更多信息:
https://my.site.com
它加载就好了。 我要重定向的应用程序驻留在另一个也有.htaccess文件的应用程序的子文件夹中。 这是该应用程序的代码:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] RewriteEngine On </IfModule>
这是萤火虫说的:
更改规则的顺序,并在其他内部重写规则之前保留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.