简体   繁体   中英

How to write rewrite rule in .htaccess file of php

I want to implement basic http authentication, and I have written in .htaccess file. I also need to check one condition if I request www.example.com it should ask me for basic authentication. 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.

Create encrypted passwords file then place this code in your .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. Then you can check your cf parameter and determine whether the link is valid one or should move to basic http authentication. For detail of implementation, you can see http://php.net/manual/en/features.http-auth.php .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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