开发者

Only allow access to directory index

I've been fiddling with this all morning, I really hope someone can help me out. I have a directory on my website which only the admins must be able to access. So I password protected it using a .htaccess file. But I want the index.php to remain accessible.

So I tried:

AuthUserFile "/home/example.com/passwords/.htpasswd"
AuthType Basic
AuthName "Admin"
require valid-user

<FilesMatch "^index\.php$">
    Satisfy Any
    Allow from all
</FilesMatch>

And yes it works, but only if you explicitly specify index.php in the URL:

http://www.example.com/admin/index.php -> OK

http://www.example.com/admin/ -> Popup crying about login

http://www.example.com/admin -> Popup crying about login

So I went on and modified the regular expres开发者_如何学Gosion:

<FilesMatch "^(|index\.php)$">
    Satisfy Any
    Allow from all
</FilesMatch>

Not the best regular expression I ever wrote but hey there's some result:

http://www.example.com/admin/index.php -> OK

http://www.example.com/admin/ -> OK

http://www.example.com/admin -> Popup crying about login

I just don't see why this doesn't work. I also tried reversing the whole thing like this:

AuthUserFile "/home/example.com/passwords/.htpasswd"
AuthType Basic
AuthName "Admin"

<FilesMatch "^(?!index\.php).+$">
    require valid-user
</FilesMatch>

But yet again to no avail... Anyone sees a solution?


I dont know how to allow the access on http://www.example.com/admin but you can avoid that the directory gets called by redirecting the access to the index.php as you can see here:

RewriteRule ^admin$ admin/index.php

or if you need get parameters

RewriteRule ^admin\/?\?([^#]*)$ admin/index.php?$1
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜