Forward slash on URLs in the Sitemap file?

by Richard   Last Updated April 27, 2019 14:04 PM - source

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?

Tags : url sitemap


Answers 1


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.

MrWhite
MrWhite
September 10, 2011 18:37 PM

Related Questions



How to test multiple Sitemap.xml file?

Updated August 28, 2019 17:04 PM


Indexing different subdomains on a sitemap

Updated July 06, 2016 09:01 AM