【发布时间】:2015-06-27 13:54:15
【问题描述】:
我看过:
Rerouting all http traffic to https with AWS ELB
http://www.emind.co/how-to/how-to-force-https-behind-aws-elb
Redirecting EC2 elb from http to https
我的负载均衡器监听端口如下所示:
HTTP (incoming) -> HTTP (instance)
HTTPS (incoming) -> HTTP (instance)
这是我目前所拥有的:
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule !/elbcheck.html https://%{SERVER_NAME}%{REQUEST_URI}
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
这适用于将 http 重定向到 https,但它只会转到索引页面。它没有触发应用程序,所有其他页面都以 404 形式返回。
任何建议都将不胜感激,我一直在努力解决这个问题太久了。
***************更新***************
这是我的.htaccess 最终的样子:
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_USER_AGENT} !^ELB-HealthChecker
RewriteRule (.*) https://sitename.com%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteRule ^.*$ index.php [NC,L]
希望这会有所帮助!
【问题讨论】:
标签: .htaccess amazon-web-services amazon-ec2 zend-framework2 amazon-elb