仅允许某些文件通过.htaccess查看 [英] Allowing only certain files to view by .htaccess
问题描述
我在服务器上有将近20页,但是我只需要一个名为abc.php的文件,用户可以观看.我想要用户是否强制打开其他文件,例如//example.com/some.php .htaccess显示403错误.
i have almost 20 pages on server, but i want only a file named abc.php, which users can watch. i want if user forcefully open the other files like //example.com/some.php .htaccess shows 403 error.
<Files ~ "^(?!(changepwd|login|register|remind|securitycode|registersuggest)\.php$).*(\.php)$">
AuthName "Reserved Area"
AuthType Basic
AuthUserFile path_to/.htpasswd
AuthGroupFile path_to/.htgroup
Order Deny,allow
Require group allowed_groups
</Files>
这是我目前使用的方式,但我认为可以有更优雅的解决方案.
this is the way i am currently using, but i think there can be more elegant solutions.
推荐答案
此.htaccess
文件仅允许用户打开index.php
.尝试访问任何其他文件将导致403错误.
This .htaccess
-file will only allow users to open index.php
. Attempts to access any other files will result in a 403-error.
Order deny,allow
Deny from all
<Files "index.php">
Allow from all
</Files>
如果您还想对某些文件使用身份验证,则只需在示例末尾添加当前文件中的内容即可.
If you also want to use authentication for some of the files, you may simply add the content from your current file at the end of my example.
这篇关于仅允许某些文件通过.htaccess查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!