大网数据广告活动
网站运营与故障问答

Wildcard matches in robots.txt that allow crawling of all JS and CSS are not working

· 52CE 我爱测

To allow the robots to crawl all CSS and JS files we have used the following code: Allow: /*.css$ Allow: /*.js$ But, some CSS and JS are still being blocked as stated when using the mobile friendly test from Google. Does the loca…

问题原文

原帖链接 · GrapeSoda · CC BY-SA 3.0

To allow the robots to crawl all CSS and JS files we have used the following code:

Allow: /*.css$
Allow: /*.js$

But, some CSS and JS are still being blocked as stated when using the mobile friendly test from Google.

Does the location of the line of code in the robots.txt file matter?

Are there instances were the line of code will be ignored?

已采纳解答

原帖链接 · Stephen Ostermiller · CC BY-SA 3.0

Robots.txt uses the longest rule that matches. So when your rules are

Disallow: /directory
Allow: /*.js

Then /directory/file.js would be blocked. Both rules match, and the longer one (the disallow rule) takes precedence. See this article which explains it.

One work around might be to use lots of stars in your wild card rules to make them longer than your other rules:

Allow: /********************.js

Here are some screenshots from Google's robots.txt testing tool showing the technique working:

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2017-01-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。