Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache保护和重写_Apache_.htaccess_Authentication - Fatal编程技术网

Apache保护和重写

Apache保护和重写,apache,.htaccess,authentication,Apache,.htaccess,Authentication,我有一个urlwww.mywebsite.com/admin,我想用这个密码保护它 AuthType Basic AuthName "Restricted Files" # (Following line optional) AuthBasicProvider file AuthUserFile /usr/local/apache/passwd/passwords Require user SomeUsername 但是,该站点使用自定义框架,因此/admin通过index.php,因此实际上

我有一个url
www.mywebsite.com/admin
,我想用这个密码保护它

AuthType Basic
AuthName "Restricted Files"
# (Following line optional)
AuthBasicProvider file
AuthUserFile /usr/local/apache/passwd/passwords
Require user SomeUsername

但是,该站点使用自定义框架,因此
/admin
通过
index.php
,因此实际上没有
admin
文件夹,因此我无法将其放入.htaccess文件中。如何使用上述代码保护该url?

您可以将
mod_setenif
mod_auth
组合如下:

SetEnvIfNoCase Request_URI /admin SECURED

AuthType Basic
AuthName "Restricted Files"
AuthBasicProvider file
AuthUserFile /usr/local/apache/passwd/passwords
Require user SomeUsername
Order allow,deny
Allow from all
Deny from env=SECURED
Satisfy any

这会直接放在我根目录中的.htaccess文件中吗?现在就放在那里,效果很好,谢谢:)