仅允许通过.htaccess查看某些文件

10 apache .htaccess mod-rewrite

我在服务器上有近20页,但我只想要一个名为abc.php的文件,用户可以观看.我想如果用户强行打开其他文件,如//example.com/some.php .htaccess显示403错误.

<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>
Run Code Online (Sandbox Code Playgroud)

这是我目前使用的方式,但我认为可以有更优雅的解决方案.

Atl*_*tle 25

这个.htaccess文件只允许用户打开index.php.尝试访问任何其他文件将导致403错误.

Order deny,allow
Deny from all

<Files "index.php">
    Allow from all
</Files>
Run Code Online (Sandbox Code Playgroud)

如果您还想对某些文件使用身份验证,则可以在我的示例末尾添加当前文件中的内容.

  • 如何允许超过1个文件?像index.php和register.php?在`<Files"index.php">允许所有</ Files>` (2认同)