I searched within the site but none where addressing exactly my question, So I ask it here:

Which one of these structures for a user-friendly url is the best with regards to search engines and user experience:




or perhaps:


In another word, Is it better to place id at the end of url or at the beginning, or maybe somewhere in the middle of it?

And another question: is it better to add a trailing slash to the end of the url?

To guess how long would be such the url the number of words in each section of the url are:

  1. Category-name: 2 words

  2. sub-category-name: 1 word

  3. su-sub-category-name: 1-4 words (average 2 words)

  4. article-namae: Average: 4 words

Thank you very much

  • 1
    It seems like your URL's are already going to be very long (possibly too long for effective search engine indexing), why do you need to include an ID in the URL? Surely the ID is not there for the user's benefit? Oct 23, 2014 at 12:20
  • @richhallstoke I want to speed up the page load. If it does not include ID,(as it is now) one step of finding the ID is added to process of loading page.
    – Ormoz
    Oct 23, 2014 at 12:22
  • 1
    Arguably the time it takes for single SQL query to lookup an ID (if you really need to work to an ID) from a URL would be insignificant, especially compared to the benefits of shorter URLs for both users and search engines. If your pages were loading slow due to database queries it would be running certainly more than 25 if not hundreds of potentially inefficient queries. 1 database query to return a single record should run so quick you can't even measure it in milliseconds. Oct 23, 2014 at 13:48
  • 1
    As best practice evolves over time, it is not always easy or practical to do everything in the best way. It might be that when your site gets as many page loads per minute as StackOverflow or StackExchange that the difference in database queries is amplified to become significant. Oftentimes SEO and friendly URLs is just not the most important thing on the to-do list. Changing things when your site is well indexed can also go catastrophically wrong if the reindexing doesn't go to plan or happen quickly, and so risk can be a factor too. Many search engines only see the first 75-90 characters. Oct 23, 2014 at 14:59
  • 1
    StackOverflow uses IDs because it is the only key that can identify a question. It is quite possible to have two question title's that would otherwise resolve to the same URL part. But also, the question title is user editable. When the title gets edited the URL changes and the site is able to redirect the old URL to the new URL only because the ID has remained constant. This redirection would be much more complex to implement if an ID was not used, as you would have to store all the previous URLs.
    – MrWhite
    Oct 23, 2014 at 16:14

1 Answer 1


There are two things you have to keep in your mind:

  1. The easier to remember, the better
  2. you have to be able to remove each part in the url without breaking it

This makes your 3 examples rather easy:

A http://www.example.com/category/sub-category/sub-sub-category/article/ID
B http://www.example.com/ID/category/sub-category/sub-sub-category/article
C http://www.example.com/category/ID/sub-category/sub-sub-category/article

The ID in B&C are too close to the domain. If you were to remove '/article' from the url, you would have to see the sub-sub-category page. The product's ID no longer makes any sense now.

That leaves A. Rule 1 fails here (you should be able to remove /ID from the url), but there is a easy fix:


I've replaced the last slash with a dash. You can easily take the id with something like:

$pid = substr($url, strrpos($url,'-')+1); // find the last dash

You can't use explode here and take the last value, it would break with /example-string-123. Wether you use id-name or name-id doesn't really matter.

Offtopic: I'd keep the url structure A, but the url to the product I try to make very short:

A http://www.example.com/article-ID
B http://www.example.com/ID-article
C http://www.example.com/Brandname-article-ID

If the product would change category, the url remains the same. Less dead links, less to worry about and shorter urls are (often) better. If you want to make the distinction a bit more easy for the code could append .htm after the url, for products only.

This allows you to display products multiple times if they fit multiple criteria. Say you have an awesome blue tshirt (ABT), you could display ABT on the /blue-stuff and /t-shirts overviews.
This is just my preference after some years of experience.

  • Thanks Martijn, Then I may include IDs in the other names too, like :/category-catID/sub-category-subID/sub-sub-category-subSubID/article-artID. Does it makes the url too long? What do you think of D http://www.example.com/category/sub-category/sub-sub-category/ID/article?
    – Ormoz
    Oct 23, 2014 at 13:51
  • 1
    An ID for a category should not be needed. The name of a category should be unique. And because it's unique, the ID is not needed, you can search based on the name/url
    – Martijn
    Oct 23, 2014 at 13:53
  • 1
    Same goes for subcategories, but those are a little trickier; There can be a blue in pants, but also a blue in t-shirts. You will have to find the sub-cat with blue as url and the 'pants' as parent
    – Martijn
    Oct 23, 2014 at 13:55
  • which is more user-friendly: http://www.example.com/Brandname/ID/article or http://www.example.com/Brandname-article-ID?
    – Ormoz
    Oct 23, 2014 at 13:59
  • 1
    /Brandname/article-ID (note the dash) or /Brandname-article-ID are fine. The first one "requires" /Brandname to exist as well (rule 2)
    – Martijn
    Oct 23, 2014 at 14:06

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