在.htaccess上配置HTTPS重定向的重定向太多

时间:2018-05-30 12:43:53

标签: .htaccess mod-rewrite https

我的网站https://example.comhttp://example.comhttps://www.example.comhttps://www.example.com工作正常。

现在我希望无论您输入哪一个,它都会重定向到https://www.example.com。我在.htaccess中使用下面的代码(并尝试了更多),但在浏览器中进行重定向后,页面不会加载,给出错误"太多的重定向"。我当然试图删除缓存。

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

2 个答案:

答案 0 :(得分:3)

由于我的主机是Heroku,它有特殊的规则,任何其他解决方案都不适合我。 .htaccess中的以下代码就像一个魅力:

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

答案 1 :(得分:0)

我有类似的问题波纹管代码解决了我的问题

if name == 'main'

RewriteEngine on RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^[DOMAIN HERE]$ RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [DOMAIN HERE] Note: Replace

相关问题