2013-04-08 126 views
1

爲了在AWS Elastic Beanstalk php應用程序上將http重定向到https,我在.htaccess文件上使用重寫規則。在Elastic Beanstalk上強制重定向http到https

我的問題是,我的規則工作的優良指向文件的URL,但不爲根域,例如:

http://www.testdomain.com/index.php => redirects OK to => https://www.testdomain.com/index.php 

http://www.testdomain.com does not redirect to https://www.testdomain.com 

我的規則:

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

感謝您的幫助!

回答

1

regular expression.需要至少一個字符。如果你想匹配任何,包括空,URL路徑兼用^^.*$

RewriteRule^https://%{SERVER_NAME}%{REQUEST_URI} [L,R] 

您還可以使用%{HTTPS}來測試SSL連接

RewriteCond %{HTTPS} off