Home  >  Article  >  Backend Development  >  .htaccess file protection example explanation_PHP tutorial

.htaccess file protection example explanation_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:31:47847browse

For example, if you want to protect the admin folder, go through the following two steps:

Step 1. You can use Notepad to create a new file .htaccess and enter the following content:

AuthType BasicAuth

UserFile D:/AppServ/www/Hill/admin/.htpasswd

AuthName “hill”

require valid-user

Not much explanation for each line, the key is the first one The second line must be an absolute path, indicating the location of the .htpasswd file. (Any location)

Then put this file named .htaccess into the admin folder.

Step 2. The following is to create a new file named .htpasswd. The name should be consistent with the second line above.

Simple method: Start-Run-cmd-apache>binhtpasswd -c .htpasswd name

The following is to enter the password, which is md5 encrypted.

After completion, place the file named .htpasswd at the location specified in the second line.

Let me explain the second line of UserFile again. It took me a long time to get it right. If it prompts a 500 error, it means the path is incorrect. The location of the atbhost space is /home/registered name.

atbhost space provides a place to store passwords: .htpasswds


Protect your .htaccess file

.htaccess is too powerful, but it will It will not be cracked. How to protect it?

A: When using .htaccess to set password protection for a directory, it contains the path to the password file. For security reasons, it is necessary to protect .htaccess so that others cannot see its contents. Although this can be done in other ways, such as permissions on the document. However, .htaccess itself can also do it, just add the following instructions:

Copy the code The code is as follows:

< ;Files .htaccess>
order allow,deny
deny from all

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322961.htmlTechArticleFor example, if you want to protect the admin folder, go through the following two steps: Step 1. You can use Notepad to create a new folder File .htaccess, enter the following content: AuthType BasicAuth UserFile D:/AppSe...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn