kml 文件类型的搜索引擎优化
我有一个生成 kml 文件的网站。像这样的 uri: /tokml?gid=2846
生成如下文件: Mt. Dana Summit Trail.kml
在 PHP 脚本中使用 Header('Content-Disposition: inline; filename="Mt. Dana Summit Trail.kml"');
并在 Apache http 服务器上运行。
但 Google 搜索 filetype:kml 不会从我的网站提供任何结果。我可以缓存所有 kml 文件并构建一个像这样的 uri:/kml/Mt. Dana Summit Trail.kml
但还有其他解决方案吗?
I've a web site that generates kml files. An uri like this:
/tokml?gid=2846
Generates a file like this:
Mt. Dana Summit Trail.kml
Using Header('Content-Disposition: inline; filename="Mt. Dana Summit Trail.kml"');
in a PHP script and running on Apache http server.
But a Google search on filetype:kml will not give any results from my web site. I could cache all kml files and build an uri like this: /kml/Mt. Dana Summit Trail.kml
But are there any other solutions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据我的经验,Google 通常会很好地在查询字符串中使用标识符来索引 URL - 因此,在搜索
filetype:kml
时什么也没有显示,这似乎很奇怪。如果您可以发布指向相关网站的链接,或者提供对/tokml?gid=2846
的请求的响应标头的完整副本,那就太好了 - 可能存在某种“拦截器”隐藏在这些标题中。为每个文档分配一个“真实”URL(不带查询字符串参数)通常是一个好主意,并且您不需要磁盘缓存 KML 文件来实现此目的。如果您的 PHP 应用程序托管在 Apache 上,您可以让 mod_rewrite 翻译漂亮的 URL通过将其包含在应用程序的
.htaccess
文件中,将其添加到查询字符串版本中:您可能需要向数据模型添加一个额外的字段,以便为每个 KML 文件保存一个“url slug”。该值通常与文件名几乎相同,但全部小写且没有任何特殊字符 - 例如。
mt-dana-summit-trail
。通过在 URL 中使用此字段而不是实际名称,用户和机器人将避免看到充满丑陋的编码字符值的 URL。每当您编写指向 KML 文件的链接时,请使用新的 URL 样式:
在您的
tokml
脚本中,检索slug
查询字符串键,并使用此 - 而不是 < code>gid - 查找相关数据对象时。请注意重写规则如何捕获 url slug 并将其作为良好的老式查询字符串参数传递给脚本。From my experience, Google usually index URLs with an identifier in the query string quite well - thus, it seems strange that nothing at all shows up when searching for
filetype:kml
. It would be nice if you could post a link to the site in question, or provide a complete copy of the response headers from a request to/tokml?gid=2846
- there might be some kind of "blocker" hidden in those headers.Assigning a "real" URL (without query string parameters) for each document is usually a good idea, and you should not need to disk cache your KML files to achieve this. If your PHP application is hosted on Apache, you can let mod_rewrite translate the pretty URLs into the query string versions, by including this in a
.htaccess
file for the application:You might want to add an extra field to your data model, to hold a "url slug" for each KML file. The value would typically be almost the same as the name of the file, but all lowercased and without any special characters - eg.
mt-dana-summit-trail
. By using this field in the URL instead of the actual name, users and robots will avoid seeing URLs full of ugly, encoded character values.Whenever you write out a link to a KML file, use the new URL style:
In your
tokml
script, retrieve thenslug
query string key, and use this - instead ofgid
- when looking up the relevant data object. Notice how the rewrite rule makes a capture of the url slug and passes it to the script as a good old fashioned query string parameter.