tags:

views:

160

answers:

1

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?

+1  A: 

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:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^kml/([^.]+)\.kml$ tokml?slug=$1 [NC]

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:

<a href="/kml/mt-dana-summit-trail.kml">Mt. Dana Summit Trail</a>

In your tokml script, retrieve then slug query string key, and use this - instead of gid - 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.

Jørn Schou-Rode
Your code won’t work in a .htaccess file.
Gumbo
he Google search site:toposhare.org filetype:kml actual gives results because I've ulrs like this: www.toposhare.org/rss2kml.kml?... I could of cause add a .kml ending to my script (tokml.kml?gid=2846) A url for kml: toposhare.org/tokml?gid=1008 How do I use the "url slug" in my urls?
Martin Hoegh
@Gumbo: thanks, bug fixed and extra options added. @Martin: using mod_rewrite you will get the `.kml` file endings, and I have added better description of the "url slug" idea.
Jørn Schou-Rode
That's great! Thanks.
Martin Hoegh