【发布时间】:2014-06-18 04:12:36
【问题描述】:
我目前已将所有http 流量重定向到https。
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteRule ^/(.*)$ https://%{SERVER_NAME}/$1 [R=301,L]
以上工作正常。
现在我正在尝试添加重写条件以强制所有 https://www 流量到 https 而没有 www。
请注意,这是在 Elastic Load Balancer 后面运行 Apache 的 AWS Elastic Beanstalk
==============================
编辑:
工作代码:
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !=https [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{SERVER_NAME} ^(www\.)?(.*)$ [NC]
RewriteRule ^/?(.*)$ https://%2/$1 [L,R=301]
【问题讨论】:
标签: apache .htaccess mod-rewrite amazon-web-services amazon-ec2