现在 .htaccess 中有一个代码只允许打开 index.php。
<Files *.php>
deny from all
</Files>
<Files index.php>
allow from all
</Files>
但是如何让 index.php 对所有人可见,而其他文件只对特定的 IP 地址可见?
现在 .htaccess 中有一个代码只允许打开 index.php。
<Files *.php>
deny from all
</Files>
<Files index.php>
allow from all
</Files>
但是如何让 index.php 对所有人可见,而其他文件只对特定的 IP 地址可见?
为了通过解析客户端的 IP 地址来允许或拒绝访问,您可以在 from 指令中指定地址或子网。此外,您必须指定默认为拒绝或允许其他地址:
您可能需要能够在 .htaccess 文件中为特定站点的 apache 使用的特定目录指定访问指令,否则可能会忽略指定的指令。
为此,请在 apache 配置文件(/etc/apache2/apache2.conf、/etc/httpd/httpd.conf)中找到并在 .htaccess 中指定要覆盖的属性(为简单起见,您可以指定它允许更改任何属性 - AllowOverride All):
.htaccess 中允许/拒绝的详细信息: https ://htaccessbook.com/block-ip-address/
目录配置中 AllowOverride 的详细信息: https ://httpd.apache.org/docs/2.4/mod/core.html#allowoverride