在Play! Framework 2.0中路由到静态文件

10
为了SEO目的,我试图通过url使一些文件可访问,例如http://example.ca/robots.txt。但是我面临着一个奇怪的问题。这些文件在firefox中可以访问,但是chrome和google机器人无法获取这些文件!
我的路由如下:
# Map static resources from the /public folder to the /assets URL path
GET     /assets/*file               controllers.Assets.at(path="/public", file)

# Robots and Humans files
GET     /$file<(robots|humans).txt>             controllers.Assets.at(path="/public", file)

GET     /$file<MJ12_576CD562EFAFA1742768BA479A39BFF9.txt>                 controllers.Assets.at(path="/public", file)

你是否遇到了404错误?你确定没有被缓存的东西导致了这个问题吗? - James Ward
1
看看另一个问题,Chrome做了奇怪的事情 :) http://stackoverflow.com/a/13103936/1066240 感谢@Schleichardt,我通过添加favicon解决了它,使用onRequest检查发生了什么。 - biesior
1
我正在测试一个空文件,似乎Chrome将空文件视为损坏的链接... - Mooh
1个回答

23

我不确定这是否会有所影响,但请尝试:

GET     /robots.txt             controllers.Assets.at(path="/public", file="robots.txt")
GET     /humans.txt             controllers.Assets.at(path="/public", file="humans.txt")

GET     /MJ12_576CD562EFAFA1742768BA479A39BFF9.txt                 controllers.Assets.at(path="/public", file="MJ12_576CD562EFAFA1742768BA479A39BFF9.txt")

favicon.ico 也使用这个。我把它放在这里供 Google 搜索使用。 - raisercostin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接