我有一个 Zend Framework 应用程序,我想使用 mod_rewrite 将其强制转换为 HTTPS。当谈到 mod_rewrite 时我非常迷失。这是我的应用程序根目录中当前的 .htaccess 文件。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule !\.(html|htm|php|js|ico|gif|jpg|png|css|csv)$ /subdir/index.php
根据我的情况,强制应用程序进入 HTTPS 的最佳方法是什么?我已经尝试了在这里找到的几个示例,但是当我尝试它们时,我不断收到重定向循环或内部服务器错误。
感谢您的帮助!
以下解决方案适用于代理服务器和非代理服务器。所以如果你正在使用CloudFlare、AWS 弹性负载平衡、Heroku、OpenShift或任何其他云/PaaS 解决方案,并且您正在经历重定向循环对于普通的 HTTPS 重定向,请尝试一下。
RewriteEngine On
# If we receive a forwarded http request from a proxy...
RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]
# ...or just a plain old http request directly from the client
RewriteCond %{HTTP:X-Forwarded-Proto} =""
RewriteCond %{HTTPS} !=on
# Redirect to https version
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Put the rest of your rewrite rules here
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)