php – How to prevent duplicate title tags on dynamic content-ThrowExceptions

Exception or error:

Links on the website I am making currently look like this:

http://www.example.net/blogs/151/This-is-a-title-in-a-url

My php system pulls out the id (151 say) and uses that to pull to content from my database. The text afterwards is effectively ignored (much like stackoverflow uses).

Now my problem is that this creates duplicate titles that Google will sometimes index and I lose SEO as a result:

http://www.example.net/blogs/151/This-is

http://www.example.net/blogs/151/

What is the best way to make it so that google and other search engines only see the correct full link so that I don’t end up with duplicates and get the best ranking possible?

EDIT: I notice that with stackoverflow site that you get dynamically redirected to another page? How do they do that?

How to solve:

Pick a URI to be canonical.

When you get a request for http://example.com/123/anything then, instead of ignoring the anything, compare it to the canonical URI.

If it doesn’t match, issue a 301 Moved Permanently redirect.


A less optimal approach would be to specify the canonical URI in the page instead of redirecting:

<link rel="canonical" href="http://example.com/123/anything"/>

Leave a Reply

Your email address will not be published. Required fields are marked *