0

I inherited the following .htaccess file from the previous web developer. I am totally baffled by some of the rules here and getting endless loops on things.

<IfModule mod_security.c>
SecRuleRemoveByID 000014
</IfModule>
RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]

# STRIP .HTML FROM DISPLAY
RewriteCond %{REQUEST_URI} !^/(dashboard|editor/.*)$
RewriteCond %{THE_REQUEST} ^(.+)\.html([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.html$ /$1 [R=301,L]

RewriteCond %{REQUEST_URI} !^/(dashboard|editor/.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.html
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.html

RewriteCond %{REQUEST_URI} !^/(dashboard|editor/.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

What I'm trying to accomplish is the following:

  1. Append www. to all incoming URLs
  2. Redirect all http requests to https
  3. Display all incoming .html URLs without the .html

We have an angular app in /dashboard and /editor and we need to make sure that we exclude those directories from any rewrite rules.

PLEASE HELP!

1 Answers1

1

turn on debugging via

LogLevel alert rewrite:trace6

(on apache2.4 and up) and trace it. see How to debug Apache mod_rewrite

I can imagine several bad news cases, including where apache is behind some sort of reverse proxy, talking to it via port 80 so the http->https rule gets re-invoked forever.

djsadinoff
  • 5,519
  • 6
  • 33
  • 40