0

I have two criteria I am trying to meet with my .htaccess file and I'm currently getting an infinite redirect loop. I need to:

  1. Ensure SSL (https) when visitors attempt to resolve to the http version of the site
  2. I'm using Angular and want to rewrite the URL

I can do these both independently as follows:

  1. .htaccess file for SSL
AddHandler application/x-httpd-php72 .php
Options +FollowSymlinks
RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
  1. .htaccess file for url rewriting to work with angular
AddHandler application/x-httpd-php72 .php
Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ /index.html [L]

Both of these work independently BUT do not work together (get the redirect loop I mentioned) with this attempted .htaccess file:

AddHandler application/x-httpd-php72 .php
Options +FollowSymlinks
RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ /index.html [L]

I want to avoid the error ERR_TOO_MANY_REDIRECTS when I attempt to access the site - has anyone any advice on how I correct the above in my .htaccess file to stop the multiple redirect loop.

Thanks in advance for any help!

Rob
  • 6,819
  • 17
  • 71
  • 131
  • 1
    _“What am I doing wrong?”_ - well so far, you’re acting as if “doesn’t work” was a valid problem description … – 04FS Sep 25 '19 at 08:23
  • Fair point!! It wasn't a great problem description - updated, hopefully clearer now - thanks! :-) – Rob Sep 25 '19 at 08:30
  • Not easily apparent to me here why this would happen. ERR_TOO_MANY_REDIRECTS sounds like an error issued by the browser, not the server - and since the only external redirect here is the HTTPS one, I’d expect that to be able to malfunction only if `%{HTTPS} off` wasn’t true even if the HTTPS URL was requested, but it doesn’t make sense that this would work on its own then. Did you forget to modify some base URL configuration setting maybe, could the application itself try to redirect from HTTPS to HTTP, because it thinks the user was on the “wrong one”? – 04FS Sep 25 '19 at 08:39
  • This is really the only config I have - it's an angular app so has only an index.html file with the set. I've never really used .htaccess files before so not sure how to resolve :-\ – Rob Sep 25 '19 at 08:43
  • Try and enable rewrite logging, https://stackoverflow.com/a/9632952/10955263, that can often help in figuring out such issues. – 04FS Sep 25 '19 at 08:47

0 Answers0