3

At the following page:

http://www.google.com/support/webmasters/bin/answer.py?answer=183668#2

the URLs given in the Sitemap example don't have a forward slash at the end.

But I think I heard somewhere that they should.

In my Sitemap file, should I include a forward slash / on the end of each URL?

Or does it not matter?

5

The URLs you use in your Sitemap should be the same canonical URLs you use on your site. If you include a trailing slash when linking between your pages then include a trailing slash in your site. Whether URLs end with a trailing slash is generally up to you - there isn't necessarily any right or wrong way of doing it.

If your URLs map directly to files on the filesystem then arguably they should only have a forward slash at the end if you are linking to a "directory" and your page is the default document within that directory eg. index.html, index.php, etc. But this should also be how you link to the page within your site. The forward slash is simply to avoid any ambiguity, to indicate it is a directory and not a file. (By default on Apache, if you link to a file system directory and omit the trailing slash then mod_dir triggers a 301 external redirect to append a trailing slash - to "fix" the URL.)

For example, it is generally preferred to not link to the default document in the directory:

http://www.example.com/path/to/index.html

You should simply show the URL as the following (with a trailing slash):

http://www.example.com/path/to/

As mentioned, the trailing slash removes any ambiguity. If you omit the trailing slash, it will probably still work, but it first looks for a file called to before realising it's a directory.

The URLs in the sitemap example at the address given do not have a forward slash at the end because they are linking to specific HTML files on the filesystem, eg. http://example.com/foo.html. In this case, if you simply append a trailing slash it will likely generate a 404 Not Found response on Apache. (Because the text/html handler does not accept path_info by default.)

Incidentally, this relates more to how you link to files within your site - not just the Sitemap.

  • thanks w3d -- so on my site, if I don't add a slash or index.php, it goes to my homepage -- does this mean i dont add the slash? the site is wordfruit.com – Richard Sep 10 '11 at 20:27
  • I think you should include the trailing slash in the sitemap URL. You do seem to be linking to "/" in your home links, so you are actually linking to http://wordfruit.com/. The browser seems to treat site-root links a bit different anyway, in that it appears to automatically append the trailing slash when a user types somedomain.com in their browser. However, sub pages do seem to be different. – MrWhite Sep 11 '11 at 0:08
  • ...Sub pages cont... for example, you link to http://wordfruit.com/copywriters, which implies a file called 'copywriters', but the actual page returned by the server is http://wordfruit.com/copywriters/index.php. The server has had to do some extra processing in order to work this out since there is no file called 'copywriters'. Ideally you should include http://wordfruit.com/copywriters/ in your sitemap (and in your site link). – MrWhite Sep 11 '11 at 0:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.