如何在 Apache 中为 CakePhp 应用程序配置密码保护例外?
我有一个 CakePHP 应用程序,我想用密码保护它。棘手的是,除了一个特定的地址(CakePHP 控制器的一个函数)之外,所有文件/位置都只能通过密码访问。
地址如下:
http://example.com/MyApp/MyController/MyFunction?MyParam=MyValue
所有其他位置只能通过密码访问
http://example.com/MyApp/MyController/MyOtherFunction
http://example.com/MyApp/MyController/MyOtherFunction
http://example.com/MyApp/MyOtherController/MyOtherFunction
嗯,我首先尝试了根 .htaccess
-File,但 CakePHP 的整个重写使其变得非常困难,并且在 .htaccess-Files 中不允许
指令。所以我用
尝试了它,但真正的文件总是相同的:index.php
。 mod_rewrite 将所有地址重写为
在下一步中,我在 apache 配置中尝试了它,并将此部分放在那里,
<LocationMatch ^/MyApp/MyController/MyFunction.*>
AuthType Basic
AuthName "Secure Area"
AuthUserFile /path/to/.htpasswd
Require user MyUser
</LocationMatch>
正则表达式匹配,但这是错误的方式。它保护 MyFunction 但不保护其余部分。
I have a CakePHP Application which I want to protect with a password. The tricky thing is, that all files/locations should be only accessible with a password EXCEPT one specific Address (a function withing a CakePHP-controller)
The Address is like that:
http://example.com/MyApp/MyController/MyFunction?MyParam=MyValue
All other locations should be only accessible with a password
http://example.com/MyApp/MyController/MyOtherFunction
http://example.com/MyApp/MyController/MyOtherFunction
http://example.com/MyApp/MyOtherController/MyOtherFunction
Well, I tried it first in the root .htaccess
-File, but the whole rewrite-thing of CakePHP makes it very difficult and in .htaccess-Files are no <LocationMatch>
directive allowed. So I tried it with <FilesMatch>
, but the real File is always the same: index.php
. mod_rewrite rewrites all Addresses to
In the next step I tried it in the apache-configuration and put there this section
<LocationMatch ^/MyApp/MyController/MyFunction.*>
AuthType Basic
AuthName "Secure Area"
AuthUserFile /path/to/.htpasswd
Require user MyUser
</LocationMatch>
Well the regex matched, but it was the wrong way. It protects MyFunction but not the rest.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用 .htpasswd 吗?您可能更好地使用 Cake Auth,然后您可以在适当的控制器中执行此操作:
Are you using .htpasswd? You might be better using Cake Auth, then you can do this in the appropriate controller: