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

I have a site with a virtual directory structure like which is actually a .htaccess rewrite to I want to password protect the folder folder with .htaccess, and know how to do that with actual folders. But I don't want to password protect the main site, and right now if I put the .htaccess file in the directory, I am protecting and I have also tried protecting

How can I protect only using .htaccess?

.htaccess contents of

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteRule ^folder/(.*)$ /f/index.php?p=$1 [PT,L,QSA]
RewriteRule ^folder/*$ /f/index.php [L,QSA]

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]


.htaccess file I tried in This successfully protects the entire site when moved into the other .htaccess file, so I know the path is correct.

AuthName "Restricted Area" 
AuthType Basic 
AuthUserFile /home/myusername/.htpasswd 
share|improve this question
I just plugged your question title into Google and found many articles that answer it far better than I ever could. – John Gardeniers Sep 8 '10 at 21:47
Hi, thanks. I've also done that and read those articles. Unfortunately, none of those answer the question, and the only question that asks the same thing as me is left unanswered. If you have found the answer, could you possibly post the link here? – jkeesh Sep 13 '10 at 4:57

First of all you shouldn't be putting that configuration (the rewrite rules) in .htaccess files, you should be putting it in the main configuration file under a Directory section (assuming you have access to that file). The Apache docs explain why.

You should check that you have the correct AllowOverride settings. If it's all setup correctly, having the .htaccess file you specified sitting in the mysite/f folder should be enough to password protect it.

share|improve this answer
I would but I don't have access to those files. Do you know if there is a workaround just using .htaccess? – jkeesh Sep 13 '10 at 4:58

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.