Search code examples
phpurlcakephpseoslug

Make slug mandatory in page URL?


I'm deciding whether or not to make the slug mandatory in order to view a submission.

Right now either of these works to get to a submission:

domain.com/category/id/1/slug-title-here

domain.com/category/id/1/slug-blah-foo-bar

domain.com/category/id/1/

All go to the same submission.

You can also change the slug to whatever you want and it'll still work as it just checks for the category, id, and submission # (in the second example).

I'm wondering if this is the proper way to do this? From an SEO standpoint should I be doing it like this? And if not, what should I be doing to users who request the URL without the slug?


Solution

  • The slug in the url can serve three purposes:

    1. It can act as a content key when there is no id (you have an id,so this one doesn't apply)
    2. When just a url is posted as a link to your site, it can let users know what content to expect because they see it in the url
    3. It can be used by search engines as a ranking signal (Google does not use url words as a ranking signal very much right now as far as I can tell)

    Slugs can create problems:

    1. Urls are longer, harder to type, harder to remember, and often get truncated
    2. It can lead to multiple urls for the same page and SEO problems with content duplication

    I am personally not a fan of using a slug unless it can be made the content key because of the additional issues it creates. That being said, there are several ways to handle the duplicate content problems.

    Do nothing and let search engines sort out duplicate content

    They seem to be doing better at this all the time, but I wouldn't recommend it.

    Use the canonical tag

    When a user visits any of the urls for the content, they should get a canonical tag like such:

    <link rel="canonical" href="http://domain.com/category/id/1/slug-title-here" />
    

    As far as Google is concerned, the canonical tag can even exist on the canonical url itself, pointing to itself. Bing has advised against self referential canonical tags though. For more information on canonical tags see: http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html

    Use 301 redirects

    Before canonical tags, the only way to avoid duplicate content would be with 301 redirects. Your software can examine the url path, and compare the slug to the correct slug. If they don't match, it can issue a 301 redirect that will send the user to the canonical url with the correct slug. The stack overflow software works this way.

    so these urls:

    domain.com/category/id/1/slug-blah-foo-bar
    domain.com/category/id/1/
    

    would redirect to

    domain.com/category/id/1/slug-title-here
    

    which would be the only url that would actually have the content.