0

I'm trying to create an .htaccess file that does the following:

1 Allows the EC2 health check URL to be hit without redirecting to https 2 Redirects all non-https traffic to https 3 Redirect calls to / to /auth/app/public/app (using https)

Items 2 and 3 work fine, but quickly the healthcheck fails and the server no longer responds. Here's the content of my .htaccess file:

RewriteEngine On

#one attempt that didn't work
#RewriteCond %{HTTP_HOST} !^my\.domain\.com$ [NC]
#RewriteCond %{REQUEST_URI} !^/healthcheck.html$
#RewriteRule ^ http://my.domain.com/$1 [R=301,L]

#another attempt that didn't work
#RewriteCond %{HTTP_HOST} !$ [NC]
#RewriteCond %{REQUEST_URI} !^/healthcheck.html$
#RewriteRule ^(.*)$ /$1 [L,QSA]

#this works
RewriteRule ^$ https://my.domain.com/auth/app/public/app/ [L]

#this works
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://my.domain.com%{REQUEST_URI} [L]

The first two commented-out attempts are from examples I found at https://serverfault.com/questions/470015/how-should-i-configure-my-elb-health-check-when-using-namevirtualhosts-and-redir and https://serverfault.com/questions/470015/how-should-i-configure-my-elb-health-check-when-using-namevirtualhosts-and-redir/597541#597541

Please let me know if you have any suggestions how I can get this working.

Community
  • 1
  • 1
Erich
  • 499
  • 1
  • 13
  • 34
  • I’d try with a simple `RewriteRule ^healthcheck\.html$ - [L]` – when the requested URL is `healthcheck.html`, then don’t rewrite anything (`-`), and make this the last rule. That should not need any additional RewriteConds. – CBroe Feb 13 '17 at 15:47

1 Answers1

0

Thank you for the reply. Before I read that, I found another post that provided a solution that is working for me. I simply added another condition to not apply the https redirect rule if the url was that of my health check page. Here is the working version of my .htaccess file:

RewriteEngine On
RewriteRule ^$ https://my.domain.com/auth/app/public/app/ [L]

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{REQUEST_URI} !^/healthcheck\.html$
RewriteRule ^ https://my.domain.com%{REQUEST_URI} [L]
Erich
  • 499
  • 1
  • 13
  • 34