2011-12-24 113 views
1

我在我的应用程序(在/.htaccess)中有一个规则,它为访问该网站设置了一个htpassword。我们需要远程服务器,因为我们不希望除我们之外的任何人看到它。仅在PHP应用程序的远程服务器上设置.htaccess规则?

但是,在本地服务器上,我不想处理htpassword混乱。有没有什么办法可以使规则只有在域不是“本地主机”或类似的类型时才有效?

我使用PHP作为后端语言,所以如果有办法我可以用PHP解决它,那将会很棒。

感谢您提前提供任何帮助。

编辑 - 违规代码:

authtype basic 
authgroupfile /dev/null 
authuserfile /path/to/htpassword 
authname "Secure Area" 
require user username 

回答

0
RewriteCond %{HTTP_HOST} your_remote_hostname 

RewriteRule行之前添加的(当然,换成你的主机名相关部分)这一条件。

+0

这不是一个'RewriteRule'不过,这是在authType /名/要求用户。我已经编辑了上面的代码以显示我的意思。 – element119 2011-12-24 01:38:30

+0

啊,对...嗯......恐怕我不确定。抱歉... – 2011-12-24 01:45:23

0

可以使用require指令:

要求所有授予 访问被允许无条件。要求全部拒绝 无条件拒绝访问。需要env env-var [env-var] ... 只有在设置了给定环境变量之一时才允许访问。要求方法http-method [http-method] ... 仅允许对给定的HTTP方法进行访问。要求expr表达式 如果expression的计算结果为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 
相关问题