我有一个规则在我的应用程序(在/.htaccess
)设置一个htpassword访问网站。我们在远程服务器上需要这个,因为我们不希望除了我们之外的任何人看到它。
然而,在本地服务器上,我不想处理htpassword混乱。是否有任何方法可以使规则仅在域不是"localhost"或类似类型的东西时有效?
我使用PHP作为后端语言,所以如果有一种方法可以用PHP解决它,那就太好了。
谢谢你的帮助。
编辑 -违规代码:
authtype basic
authgroupfile /dev/null
authuserfile /path/to/htpassword
authname "Secure Area"
require user username
http://httpd.apache.org/docs/current/howto/auth.html#satisfy
AuthType Basic
AuthName intranet
AuthUserFile /www/passwd/users
AuthGroupFile /www/passwd/groups
Require group customers
Order allow,deny
Allow from internal.com
Satisfy any
RewriteCond %{HTTP_HOST} your_remote_hostname
在RewriteRule
行之前添加该条件(显然将相关部分替换为您的主机名)
你可以使用require指令:
要求全部授予允许无条件访问。要求全部拒绝无条件拒绝访问。env-var [env-var]…只有在设置了给定的环境变量之一时才允许访问。请求方法http-method [http-method]…只允许访问给定的HTTP方法。要求表达式如果表达式求值为true,则允许访问
mod_authz_user提供的一些允许的语法,Mod_authz_host和mod_authz_groupfile分别为:
Require user userid [userid] ... Only the named users can access the resource. Require group group-name [group-name] ... Only users in the named groups can access the resource. Require valid-user All valid users can access the resource. Require ip 10 172.20 192.168.2 Clients in the specified IP address ranges can access the resource.
authtype basic
authgroupfile /dev/null
authuserfile /path/to/htpassword
authname "Secure Area"
require user username
require ip 10.10.10.10