S
S
Shimpanze2019-02-06 17:00:48
Apache HTTP Server
Shimpanze, 2019-02-06 17:00:48

Is it possible to set the execution order of scripts in the .htaccess file?

Good afternoon!
Set a password for a folder on the server. I put the .htaccess file with the contents in the folder itself:

# Редирект всех страниц с http:// на https://
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

# И только теперь просим ввести пароль
AuthType Basic
AuthName "Пожалуйста, авторизуйтесь"
AuthUserFile полный/путь/на_сервере/.htpasswd
require valid-user

Why do I have to log in to the server twice? Am I the first to install the code that redirects to https?
And now, I go to my site (I just enter the name: site.ru), it asks to log in, and then jumps to https and again requires authorization.
Question: how to ask for authorization AFTER a redirect to https has occurred?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Satisfied IT, 2019-02-06
@Shimpanze

If I'm not mistaken, if else conditions are supported, something like this

<If "%{HTTPS} == 'on'">
  AuthName "Files are protected, enter your normal website email and password"
  AuthType Basic
  AuthUserFile /home/sites/mysite.co.uk/.htpasswd
  Require valid-user
</If>
<Else>
  RewriteEngine On
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</Else>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question