Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My .htaccess file works fine for everything expect 1 specific folder. As result, unexpectedly goes to 401 error page instead of loading index.php from administration folder.

So, for administration folder, I wish to:

1)always replace http with https for administration folder (for other folders, the last part of .htaccess works fine).

2) do not redirect urls, if they go to administration folder.

3) All rules after 1) and 2) are voided for administration folder.

I've tried to add 2) and 3) to .htaccess. So, now my .htaccess file looks like:

#adds www - always, for any url, for any folder
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*)$$1 [R=301,L]

#special rules for administration folder only - set https if not https
RewriteCond %{REQUEST_URI} ^/administration
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L=301]

#all requests to administration folder should stop here
RewriteCond %{REQUEST_URI} ^/administration
RewriteRule ^ - [L]

#some rules below - not for administration folder

But, it goes to 401 error page if I type anyway, although I wish it goes to All the rest works perfect.

If I remove .htaccess, it goes directly to any of

with no problems.

Thank you in advance.

share|improve this question

401 responses mean Authorization required and prompt your browser to ask you for a username and password. They are not controlled by mod_rewrite but rather by one of the authorization modules.

You must have some Auth* directives in either your .htaccess file or your main Apache config.

I suspect the authorization modules are triggered before the rewrite module so you have to have a valid user before any of the rewrites are processed.

What do you get when you provide a valid username and password ?

share|improve this answer
Thank you for the question. There are 2 .htaccess files: one in the root folder, the code is above. And another .htaccess file is in administration folder as well (.htpasswd is in administraion/secret). The second .htaccess is needed to enter a password only, no other rules are in it. So, #2 allows access upon correct password only, works fine. But not in case when I type, it asks the password, but sends me to anyway.:( – Haradzieniec Feb 3 '12 at 11:58
@Haradzieniec Typically, that means that it thinks you've entered the wrong password. How's the authentication configured? – Shane Madden Feb 3 '12 at 20:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.