问题原文
原帖链接 · 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:
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
