S
S
Shimpanze2019-02-26 05:09:20
Apache HTTP Server
Shimpanze, 2019-02-26 05:09:20

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

Thank you! (ready to fund a bottle :) )

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2019-02-26
@Stalker_RED

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 question

Ask a Question

731 491 924 answers to any question