ZmeY2014-11-06 16:48:18
Apache HTTP Server
ZmeY, 2014-11-06 16:48:18

Apache authorization + mod_rewrite - why is the redirect not happening?

Good afternoon!
there is a website, domain name, for example, domain.com
the website is available via http and https protocols, there is an administrative directory via domain.com and www.domain.com domain names , /admin/ you need to make it available ONLY via https protocol and ONLY by the name www.domain.com when accessing via the http protocol or by the name domain.com - you need to redirect to the correct option: domain.com/admin -> https://www.domain.com/admin/ on the server, put in the admin directory .htaccess file

this content (password file is also present):
Options FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/admin/$1 [R=301,L]
AuthUserFile /home/www/domain.com/www/admin/.htpasswd
AuthName "Enter password for access:"
AuthType Basic
require valid-user
trying to access domain.com/admin(tried Google Chrome) - instead of the expected redirect, I get a password entry window, after entering the password - a redirect to the desired address, the password entry window again (because the browser considers the resources different), re-entering the password
in general, the essence of the question is: why did the redirect not occur to the desired address IMMEDIATELY, before Apache authorization?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Boris Benkovsky, 2014-11-06

I will assume that .htaccess works for every directory, and since you have auth* directives in the root, then it uses them. Try putting auth in /admin/.htaccess

ZmeY, 2014-11-06

2 benbor
is exactly there, all in one .htaccess file in the admin directory

on the server in the admin directory I put the .htaccess file of the following content (the file with passwords is also present)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question