If statements in .htaccess files, to enable password protection when in specific directory only

孤街醉人 提交于 2019-12-24 05:22:24

问题


I have 2 copies of my website synced with Subversion. One live version and one developer version. What I like to do is to password protect the developer version, using a .htaccess file:

AuthType Basic
AuthName "Restricted Files"
AuthUserFile ../.htpasswd
AuthPGAuthoritative Off
Require user dev 

Is there a way to sync this .htaccess file to the live version without the password protection there?

I was thinking about something like

[if file exists ../.htpasswd]
  AuthType Basic
  AuthName "Restricted Files"
  AuthUserFile ../.htpasswd
  AuthPGAuthoritative Off
  Require user dev 
[/if]

or

[if currentDir = /path/to/dev/version]
...
[/if]

回答1:


Finaly found the answer over here: How can I password protect dev but not live while using SVN?

If mod_setenvif is enabled one can set different env vars

SetEnvIfNoCase ^HOST$ .+ unauthenticated
SetEnvIfNoCase ^HOST$ ^dev\.example\.com$ !unauthenticated


来源:https://stackoverflow.com/questions/5471306/if-statements-in-htaccess-files-to-enable-password-protection-when-in-specific

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!