Answer the question
In order to leave comments, you need to log in
I ask for help from experienced developers, how to make such a condition in .htaccess on Apache 2.0?
Hello!
I have hosting from REG.RU, which, for some unknown reason, put on their hostings an ancient version of Apache 2.0, which does not support the conditions ( <if...
). And they don't want to upgrade.
I need to immediately redirect to https when entering the site and put a password on the site through the .htaccess file.
In this case, a problem arises:
- first, the password entry works (on http);
- then there is a redirect to https;
- and, in conclusion, the window for entering the password AGAIN pops up (the site is already on https).
As I said, conditions are not supported.
How to get out of the situation? First redirect to https, AND ONLY THEN enter the password.
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
AuthType Basic
AuthName "Пожалуйста, авторизуйтесь на сайте"
AuthUserFile .../site.ru/.htpasswd
require valid-user
Answer the question
In order to leave comments, you need to log in
SetEnvIf %{SERVER_PORT} ^443$ HTTPS # устанавливаем переменную HTTPS
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
AuthType Basic
AuthName "Пожалуйста, авторизуйтесь на сайте"
AuthUserFile .../site.ru/.htpasswd
require valid-user
Allow from env=HTTPS # если не установлена HTTPS - не запрашиваем
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question