Apache www在Amazon Elastic Beanstalk上非wwwredirect
我最近将一个简单的PHP站点移到了Elastic Beanstalk,但是我发现很难将www.example.comredirect到example.com 。 这不是https, 我发现的大部分build议都与之相关 。 这是我的: Route53: A example.com example.eu-west-1.elasticbeanstalk.com (Alias) CNAME www.example.com example.eu-west-1.elasticbeanstalk.com 在我的.htaccess文件中,我有以下几点: <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^ %{ENV:PROTO}://%1%{REQUEST_URI} [R=301,L] </IfModule> 访问example.com一切正常,但访问www.example.com给我一个redirect循环: http://www.example.com/var/www/html/://example.com/var/www/html/://example.com 这是在AWS上redirect的最佳方式吗? 编辑 我现在也试过了 RewriteCond %{HTTP:X-Forwarded-Proto} !=https [OR] RewriteCond %{HTTP_HOST} ^www\. [NC] RewriteCond %{SERVER_NAME} ^(www\.)?(.*)$ [NC] RewriteRule ^/?(.*)$ http://%2/$1 [L,R=301] 而www.example.com确实redirect到example.com ,现在它有redirect循环(虽然在地址栏中没有服务器path)。