URL 任何部分中的字符串的 RewriteCond

RewriteCond for string in ANY part of URL

我正在尝试编写一条规则,规定 URL 不得在 REQUEST_URI 变量的任何部分包含文本“站点地图”:

RewriteCond %{HTTP_USER_AGENT} googlebot|Chrome-Lighthouse|google-structured-data-testing-tool|semrushbot|applebot|bingbot|yandex|baiduspider|ahrefsbot|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest\/0\.|pinterestbot|slackbot|vkShare|W3C_Validator|whatsapp [NC,OR]
RewriteCond %{QUERY_STRING} _escaped_fragment_
RewriteCond %{REQUEST_URI} ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.m4v|\.torrent|\.ttf|\.woff|\.svg))
   
RewriteCond %{REQUEST_URI} !sitemap
RewriteRule ^(index\.html|index\.php)?(.*) https://service.prerender.io/%{REQUEST_SCHEME}://%{HTTP_HOST}/ [P,L]

但是好像不行。如果 url 是 https://new.mysite.com/sitemap

它仍在重写 URL,即使它应该与站点地图匹配。它还需要忽略 url 的规则,例如:https://new.mysite.com/sitemap/users/1 等..

您可以将 REQUEST_URI 替换为 THE_REQUEST 变量,因为 REQUEST_URI 可能会随其他规则发生变化,例如将所有 URI 转发到 index.php 的前端控制器。

RewriteCond %{HTTP_USER_AGENT} googlebot|Chrome-Lighthouse|google-structured-data-testing-tool|semrushbot|applebot|bingbot|yandex|baiduspider|ahrefsbot|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest\/0\.|pinterestbot|slackbot|vkShare|W3C_Validator|whatsapp [NC,OR]
RewriteCond %{QUERY_STRING} _escaped_fragment_ [NC]
RewriteCond %{REQUEST_URI} !\.(js|css|xml|less|png|jpe?g|gif|pdf|doc|txt|ico|rss|zip|mp3|rar|exe|wmv|doc|avi|ppt|mpe?g|tif|wav|mov|psd|ai|xls|mp4|m4a|swf|dat|dmg|iso|flv|m4v|torrent|ttf|woff|svg)$ [NC]
RewriteCond %{THE_REQUEST} !/sitemap[/?\s] [NC]
RewriteRule ^(index\.html|index\.php)?(.*) https://service.prerender.io/%{REQUEST_SCHEME}://%{HTTP_HOST}/ [P,L]