【问题标题】:How to write rewrite rule in .htaccess file of php如何在php的.htaccess文件中编写重写规则
【发布时间】:2013-10-15 09:23:49
【问题描述】:
我想实现基本的http认证,我写在.htaccess文件里。
如果我请求www.example.com,我还需要检查一个条件,它应该要求我进行基本身份验证。如果其他应用程序包含链接,例如www.example.com/main/newscorm/start.php?page_id=10&cidReq=U8COACHINGCERTIFICAT&cf=ad4d82421f7e2a66906a0177bf132221 如果我点击此链接,它不应该要求我进行基本身份验证,我如何为此编写规则。
【问题讨论】:
标签:
php
regex
apache
.htaccess
【解决方案1】:
创建加密密码文件,然后将此代码放在您的 .htaccess 中:
# set env variable SECURED if current URI is /
SetEnvIfNoCase Request_URI "^/?$" HOME
# invoke basic auth if SECURED is set
AuthType Basic
AuthName "My Protected Area"
AuthUserFile /full/path/to/passwords
Require valid-user
Satisfy any
Order allow,deny
Allow from all
Deny from env=HOME