简体   繁体   中英

HTTPS redirection on AWS ELB

We have web servers running Apache behind an AWS ELB. I have setup the ELB to accept HTTPS connections, and send the requests over HTTP to the webservers. This works fine.

I have also redirected all the requests to ELB from HTTP to HTTPS using HTTP:X-Forwarded-Proto.

I have added the below virtualhost section to my httpd.conf file and restarted Apache. This setup is redirecting HTTP requests to HTTPS but it is landing on the Apache home page instead of the expected site.

ServerName www.myexample.com
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule !/index.html https://%{SERVER_NAME}/%{REQUEST_URI} [R=301,L]

The configuration seems to be simple and straightforward but not working.

Please let me know what is wrong in the above setup and why is it landing on the Apache home page.

You should escape the . in your rewrite rule. Change your Rewrite to be:

RewriteRule "!/index\.html" https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Also, as in the comment to your OP Remove the slash between %{HTTP_HOST}%{REQUEST_URI}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM