1

I have looked at:

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

My load balancer listening ports looks like this:

HTTP (incoming) -> HTTP (instance)
HTTPS (incoming) -> HTTP (instance)

here is what I have so far:

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]

this works in redirecting http to https however it will only go to the index page. It is not firing the application, all other pages come back as 404s.

any advice would be greatly appreciated, I have been banging my head on this one for way too long.

***************UPDATE***************

Here is what my .htaccess ended up looking like:

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]

Hope this helps!

gmaniac
  • 940
  • 1
  • 17
  • 33

2 Answers2

0

Instead of coming up with my own answer and to give credit where due, I think this is the best solution.

ELB and Apache configuration for HTTPS website

Community
  • 1
  • 1
lumberjacked
  • 966
  • 1
  • 21
  • 35
0

Also ensure that a Listener is added to ELB through AWS console. A Listener for port 80 and port 443.