HTACCESS presmerovanie na HTTPS spôsobuje ERR_TOO_MANY_REDIRECTS v localhost
- Jakub Durdík
- Člen | 1
Ahojte,
Mam problem s testovanim webu cez localhost. Web funguje naživo bez problemov cez websupport, no ked si rovnakú aplikáciu spustím cez localhost, objaví sa hláška ERR_TOO_MANY_REDIRECTS. Je to zrejme spôsobené nastavením HTACCESS, ktorý mam momentalne takto:
<IfModule mod_autoindex.c>
Options -Indexes
</IfModule>
# enable cool URL
<IfModule mod_rewrite.c>
RewriteEngine On
# RewriteBase /
# prevents files starting with dot to be viewed by browser
RewriteRule /\.|^\.(?!well-known/) - [F]
RewriteCond %{HTTP_HOST} ^mojweb.sk
RewriteRule ^(.*)$ https://www.mojweb.sk/$1 [R=permanent,L]
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
# front controller
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(pdf|js|ico|gif|jpg|png|css|rar|zip|tar\.gz|map)$ index.php [L]
</IfModule>
# enable gzip compression
<IfModule mod_deflate.c>
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/json application/xml image/svg+xml
</IfModule>
</IfModule>
Po zakomentovaní kódu:
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] `
sa aplikacikácia v localhoste už spustí. Aké má byť správne nastavenie? v diskusii htaccess too many redirects pri odkomentovani https sa tento problem už riešil, no v mojom projekte to nefunguje. Viete v čom môže byť problém?
Použitá verzia nette: 2.4.4.
- Matey
- Člen | 142
Ahoj, tuším som mal podobný problém, teraz používam:
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Je to funkčné na localhoste (vhost) aj na websupporte.
Celkovo aby som nebol viazaný na jednu domenu tak:
# no subdomain to https://www
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# no https to https://
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# prevents files starting with dot to be viewed by browser
RewriteRule /\.|^\.(?!well-known/) - [F]
Editoval Matey (11. 2. 2019 13:35)