【发布时间】:2026-01-07 20:00:01
【问题描述】:
目前我有以下规则:
- 如果用户是 Yandexbot 或 bingbot,则为除 index.html 之外的所有页面提供 403 错误
RewriteCond %{HTTP_USER_AGENT} YandexBot|bingbot [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(index\.html) [NC]
# RewriteRule ^(.*)$ /index.html? [L]
RewriteRule .* - [F]
但我发现这条规则会阻止这些机器人访问http://example.com。当机器人请求这些 URL 时,我将提供没有 301 的“index.html”。
http://example.com
http://example.com/
http://example.com/index.html
但我希望这些机器人不要访问这些 URL。我的意思是域名后面不会有任何字符:
http://mywebsite.com/?aaa
ttp://mywebsite.com/abcd
http://mywebsite.com/1234some
htaccess 文件如何?
【问题讨论】:
-
嗯,所以它可以访问除
.+而不是.*之外的任何内容? (并检查RewriteCond中的空QUERY_STRING。
标签: apache .htaccess mod-rewrite