.htaccess 目录
Protecting files on your website from unauthorized users can be very important. Even more important is the method by which you accomplish this task. You could use PHP to listen for login authorization information on each page, but that doesn't protect your images, documents, and other media, does it? That's why I've found the .htaccess
method of protecting files and directories the most reliable. Oh, and it's easy too!
保护您网站上的文件免受未经授权的用户的侵害非常重要。 更为重要的是完成此任务的方法。 您可以使用PHP侦听每个页面上的登录授权信息,但这不能保护您的图像,文档和其他媒体,对吗? 这就是为什么我发现保护文件和目录的.htaccess
方法最可靠的原因。 哦,这也很容易!
The system requires two files -- the .htaccess
file and .htpasswd file
.
系统需要两个文件.htaccess
文件和.htpasswd file
。
.htaccess代码 (The .htaccess Code)
AuthType Basic
AuthName "restricted area"
AuthUserFile /home/davidwalsh/html/protect-me-dir/.htpasswd
require valid-user
The above code protects a directory called "protect-me-dir" at root level. The "AuthUserFile" value is always specific to your hosting configuration. If you don't know what the value should be, do a phpinfo()
and find the DOCUMENT_ROOT
value.
上面的代码在根级别保护一个名为“ protect-me-dir”的目录。 “ AuthUserFile”值始终特定于您的托管配置。 如果您不知道该值是什么,请执行phpinfo()
并找到DOCUMENT_ROOT
值。
.htpasswd代码 (The .htpasswd Code)
davidwalsh:daWHfZrDLB88.
rodstewart:roFulYxC2.8ws
cssexpert:csmnmq.M8T5ho
The .htpasswd
file contains the usernames and passwords of allowed users. One per line. The passwords are MD5'd for security purposes.
.htpasswd
文件包含允许用户的用户名和密码。 每行一个。 为了安全起见,密码是MD5密码。
To generate encrypted passwords for your .htpasswd
file, you can use my .htaccess password generator.
要为您的.htpasswd
文件生成加密密码,可以使用.htaccess密码生成器 。
翻译自: https://davidwalsh.name/password-protect-directory-using-htaccess
.htaccess 目录