统一使用新式 Require 语法,并调整规则顺序

 

1. 编辑 .htaccess 文件
sudo nano /var/www/html/.htaccess

2. 替换相关授权部分
将原有的 Files 和 FilesMatch 块(包括 Order/Deny/Allow)替换为以下内容:

# 允许 ads.txt 被访问
<Files "ads.txt">
Require all granted
</Files>

# 保护其他敏感文件(仅拒绝明确的扩展名,不涉及 .txt)
<FilesMatch "\.(ini|log|sh|sql|tpl)$">
Require all denied
</FilesMatch>

说明:
不再拒绝所有 .txt 文件,因为 ads.txt 需要公开,且其他 .txt 文件(如 robots.txt)通常也是公开的。
如果确实需要拒绝其他 .txt 文件,可以采用更精确的正则,但建议先采用以上简化方案测试。

3. 保存文件并测试
curl -I https://www.xxx.com/ads.txt
预期输出应为 HTTP/1.1 200 OK 或 404 Not Found(如果文件不存在),而非 403。


登陆