Search code examples
.htaccess

Why my specific .htaccess for laravel and angular doesn't work?


my htaccess:

Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers "*"
Header set Access-Control-Allow-Methods "*"
RewriteEngine on

# Force https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteCond %{REQUEST_URI} !\.(?:css|js|jpe?g|gif|png|tff)$ [NC]
RewriteRule ^(.*) /index.html [NC,L]

it causes and error "ERR_TOO_MANY_REDIRECTS"_______________________________________________


Solution

  • I replaced this code

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

    into this

    SetEnvIf X-HTTPS 1 HTTPS
    RewriteBase /
    RewriteCond %{HTTP:X-HTTPS} !1
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
    

    I dont know what is he doing but it works