Best way to format pretty URLs for numeric IDs

后端 未结 10 1862
谎友^
谎友^ 2021-02-02 02:48

Alright, so let\'s say I\'m writing a forum application, and I want pretty URLs. However, all my tables use numeric IDs, so I\'m not sure the best way to format the URLs for tho

相关标签:
10条回答
  • 2021-02-02 03:26
    1. Doesn't include the title, so you'll lose the additional SEO value of having those keywords in the URL.

    2. Won't work well, because it doesn't have a unique numerical ID, so what are you going to do if someone else tries to post a topic titled "This is a forum post"? Then you start getting into the weird thing digg does, where it has to give the second one the url "http://www.example.com/topic/this-is-a-forum-post_2", and so on. It makes it harder to take the URL they tried to load, and figure out exactly which topic they were trying to get to.

    3. Has the best of both worlds, this would be my style of choice.

    0 讨论(0)
  • 2021-02-02 03:30

    For SEO/traffic, definitely no.2 without a doubt. Get those meaningless numbers out of the URL every single time.

    www.example.com/topic/this-is-a-forum-post

    pickup the "this-is-a-forum-post" from your database and map it back to the ID number within your database via a query. Then do an internal URL re-write to the real page, something like /topic.php?ID=324342

    0 讨论(0)
  • 2021-02-02 03:33

    i would suggest the first one, since the topic title can be changed for clarity, by the admins and then the url will be inconsistent.

    www.example.com/topic/123456
    

    also allows one to just edit the last bit of the url (the numbers and jump to another topic), not likely to happen but still a usable feature.

    0 讨论(0)
  • 2021-02-02 03:35

    Stackoverflow seems to using pattern 3, with the title being ignored completely (just the id is used).

    That makes for nice semantic URL, and is also easy to implement, and still works if the title changes later.

    Of course, the title could be completely fake:

    Best way to format pretty URLs for numeric IDs

    0 讨论(0)
  • 2021-02-02 03:36

    I'll go for the first one. You know it really doesn't matter now. Since there are Long URLs converter and it will just proliferate and will become the norm in the future. Remember the longer your URL the less SEO points you'll get.

    And you can't control the way people name their forum topics. So really, I'll just choose the first one for simplicity and the norm.

    0 讨论(0)
  • 2021-02-02 03:37

    I would go with option 3, and make the slug (the last bit) optional

    Because?

    • The ID will always be unique... 2 people may make a thread with the name 'good news' for example
    • The search bots can access the slug for some SEO goodness
    • The slug should be optional ... Using just the ID should still give you access to the site. Perhaps if the slug isn't there you could forward to the slug'd version, if you're concerned about duplicate content. You could always use the canonical meta tag to tell Google to index the slugged version.
    • Another benefit of the optional slug is if someone copies and pastes the URL into a document, there is a chance it could have characters at the end chopped off (because URLs generally don't have spaces, so they don't break to new lines). Having the slug optional means there is more of a chance people will find your page.

    I believe this is what Stack Overflow does.. and also notice they are doing rather well in the Search Engines.

    Update

    From the comments, be sure to 301 redirect any missing slug version to the correct slug.

    0 讨论(0)
提交回复
热议问题