1

I’m using friendly URLs, like so:

http://localhost/gallery/photo/this-is-a-url-friendly-photo-caption

On the friendly URL, I need to add the ID of the photo, but looking around, I’ve seen two ways of adding the ID to the friendly URL, pre and post, like so

http://localhost/gallery/photo/this-is-a-url-friendly-photo-caption.529

or

http://localhost/gallery/photo/529/this-is-a-url-friendly-photo-caption

Is there an advantage using one way? Or it’s just a question of preference / personal taste?

unor
  • 92,415
  • 26
  • 211
  • 360
Marco
  • 2,687
  • 7
  • 45
  • 61

1 Answers1

2

A small advantage of having the ID in the second last and the slug in the last path segment (/gallery/photo/529/this-is…):

In some contexts the URL might get cut off, for example by a line break in plain text emails. If the ID comes before the (usually long) slug, there’s a higher chance that the ID stays intact and the URL can keep functioning (assuming that you redirect to the canonical variant with slug).

Example

Your question currently has this URL:

https://stackoverflow.com/questions/27343034/seo-friendly-url-where-to-add-the-id

When it gets cut off like that (= the ID stays intact), it redirects to the canonical variant and the user is happy:

https://stackoverflow.com/questions/27343034/seo
-friendly-url-where-to-add-the-id

But when it gets cut off like that (= a different ID), the user is not so happy (because the link leads to a different page):

https://stackoverflow.com/questions/273430
34/seo-friendly-url-where-to-add-the-id

Community
  • 1
  • 1
unor
  • 92,415
  • 26
  • 211
  • 360