简体   繁体   English

如何在PHP的.htaccess文件中编写重写规则

[英]How to write rewrite rule in .htaccess file of php

I want to implement basic http authentication, and I have written in .htaccess file. 我想实现基本的HTTP身份验证,并且已经在.htaccess文件中编写了文件。 I also need to check one condition if I request www.example.com it should ask me for basic authentication. 如果我请求www.example.com ,我还需要检查一种情况,它应该询问我基本身份验证。 If other application contains link eg www.example.com/main/newscorm/start.php?page_id=10&cidReq=U8COACHINGCERTIFICAT&cf=ad4d82421f7e2a66906a0177bf132221 and if I click on this link it should not ask me for basic authentication, how i write a rule for that. 如果其他应用程序包含链接,例如www.example.com/main/newscorm/start.php?page_id=10&cidReq=U8COACHINGCERTIFICAT&cf=ad4d82421f7e2a66906a0177bf132221并且如果我单击此链接,则不应要求我进行基本身份验证,我应如何为此编写规则。

Create encrypted passwords file then place this code in your .htaccess: 创建加密的密码文件,然后将此代码放在您的.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

You should rather implement basic http authentication on php, not by .htaccess. 您应该在php上实现基本的http身份验证,而不是通过.htaccess。 Then you can check your cf parameter and determine whether the link is valid one or should move to basic http authentication. 然后,您可以检查cf参数并确定该链接是否有效,或者应该转到基本的http身份验证。 For detail of implementation, you can see http://php.net/manual/en/features.http-auth.php . 有关实现的详细信息,请参见http://php.net/manual/en/features.http-auth.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM