.htaccess:不同主机的不同AuthUserFile路径
我正在开发一个应用程序,它既要在本地运行,也要在远程服务器上运行。一个目录使用.htaccess:不同主机的不同AuthUserFile路径,.htaccess,.htpasswd,.htaccess,.htpasswd,我正在开发一个应用程序,它既要在本地运行,也要在远程服务器上运行。一个目录使用htpasswd文件进行保护。这是我在htaccess文件中定义htpasswd文件路径的方法: AuthUserFile ../app/some-folder/.htpasswd 不幸的是,服务器上需要app文件夹,但本地没有。相反,路径必须如下所示: AuthUserFile /Volumes/some/very/long/path/some-folder/.htpasswd 我们是否可以使用en if/els
htpasswd
文件进行保护。这是我在htaccess
文件中定义htpasswd
文件路径的方法:
AuthUserFile ../app/some-folder/.htpasswd
不幸的是,服务器上需要app
文件夹,但本地没有。相反,路径必须如下所示:
AuthUserFile /Volumes/some/very/long/path/some-folder/.htpasswd
我们是否可以使用en if/else语句根据当前主机切换此AuthUserFile路径(编辑:或者更好,不需要任何本地身份验证)?或者有没有其他解决方法可以让这个文件在我的本地主机和远程主机上工作?没关系,我找到了。我把它放在我的
.htaccess
:
AuthName "Protected"
AuthType Basic
AuthUserFile path/to/.htpasswd
Require valid-user
Order deny,allow
Deny from all
Allow from 127.0.0.1
Satisfy Any
这使得从本地IP建立的任何连接都可以通过,而无需输入密码。不完美,但在我的情况下可以工作。对于Apache 2.4+,您可以在
.htaccess
中使用If
指令和%{HTTP\u HOST}
<If "%{HTTP_HOST} == 'localhost'">
AuthUserFile /development-path/.htpasswd
</If>
<Else>
AuthUserFile /production-path/.htpasswd
</Else>
AuthUserFile/development path/.htpasswd
AuthUserFile/production path/.htpasswd