我在服务器上有将近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>
这是我目前使用的方式,但我认为可以有更优雅的解决方案。
该.htaccess
文件仅允许用户打开index.php
。尝试访问任何其他文件将导致403错误。
Order deny,allow
Deny from all
<Files "index.php">
Allow from all
</Files>
如果您还想对某些文件使用身份验证,则只需在示例末尾添加当前文件中的内容即可。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句