Is there a way to set the order of execution of scripts in the file .htaccess?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
20 views
Good day!

Set a password on a folder on the server. In the folder put file .htaccess with the contents:

# Redirect all pages from http:// to https:// RewriteEngine On RewriteCond %{SERVER_PORT} !^443$ RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] # And only now asking to enter password AuthType Basic AuthName "Please log in" AuthUserFile full/path/nasserver/.htpasswd require valid-user


Why does the server have to login twice? I first installed the code that redirects to https?

And now, I go to their website (just insert the name: site.ru), it asks to login, and then switches to https and again requires authentication.

Question: how to ask for login AFTER redirect to https occurred?

Thank you!
by | 20 views

2 Answers

0 like 0 dislike
If I am not mistaken we supported the conditions of the if-else statement, something like this
AuthName "Files are protected, enter your normal website email and password" AuthType Basic AuthUserFile /home/sites/mysite.co.uk/.htpasswd Require valid-user \rRewriteEngine On RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
by
0 like 0 dislike
For Apache versions below 2.4 you can use an ErrorDocument.
In the site root to create the file 401.php c this content:
<?php\r\rif ($_SERVER['SERVER_PORT'] != '443') {\rheader('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], true, 301);\rexit;\r}\r\r?>\r\r401 Unauthorized\rUnauthorized\r

And in the file .htaccess add the line:
An ErrorDocument 401 /401.php
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
0 like 0 dislike
1 answer
asked Sep 3, 2019 by mega-epic
0 like 0 dislike
1 answer
asked Aug 2, 2019 by mega-epic
110,608 questions
257,186 answers
0 comments
28,117 users