Server Fault Asked by jkeesh on January 1, 2022
I have a site with a virtual directory structure like mysite.com/folder/title
which is actually a .htaccess rewrite to mysite.com/f/index.php?p=title
. 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 mysite.com
, and right now if I put the .htaccess file in the mysite.com
directory, I am protecting mysite.com
and mysite.com/folder
. I have also tried protecting mysite.com/f
.
How can I protect only mysite.com/folder
using .htaccess?
.htaccess contents of mysite.com
.
<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]
</IfModule>
.htaccess file I tried in mysite.com/f
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
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.
Answered by imoatama on January 1, 2022
3 Asked on January 1, 2021 by user14108508
0 Asked on December 31, 2020 by xdg
1 Asked on December 31, 2020 by qneville
0 Asked on December 31, 2020 by dimitri-l
1 Asked on December 30, 2020 by pansal
1 Asked on December 30, 2020 by dagda1
2 Asked on December 30, 2020 by hellb0y77
1 Asked on December 30, 2020 by patrick-hund
0 Asked on December 29, 2020 by pairwiseseq
0 Asked on December 29, 2020 by shahrear-bin-amin
1 Asked on December 29, 2020 by mpen
3 Asked on December 29, 2020 by amanahumpa
3 Asked on December 28, 2020 by timanderson
1 Asked on December 28, 2020 by mgutt
1 Asked on December 28, 2020
0 Asked on December 27, 2020 by andrey-salnikov
2 Asked on December 27, 2020 by jason-cohen
1 Asked on December 27, 2020
1 Asked on December 27, 2020 by neel
Get help from others!
Recent Questions
Recent Answers
© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP