0

My .htaccess file works fine for everything expect 1 specific folder. As result, http://www.mydomain.com/administration/index.php 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} !^www.mydomain.com$ RewriteRule ^(.*)$ http://www.mydomain.com/$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 mydomain.com/administration/index.php anyway, although I wish it goes to https://www.mydomain.com/administration/index.php. All the rest works perfect.

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

http://www.mydomain.com/administration/index.php https://www.mydomain.com/administration/index.php 

with no problems.

Thank you in advance.

1 Answer 1

1

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 ?

2
  • 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 www.domain.com/administration/index.php, it asks the password, but sends me to www.mydomain.com/401.shtml anyway.:( Commented Feb 3, 2012 at 11:58
  • @Haradzieniec Typically, that means that it thinks you've entered the wrong password. How's the authentication configured? Commented Feb 3, 2012 at 20:08

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.