Question

I'm using pretty URLs in my web app, one example is 'forum/post/1' which invokes PostController in Forum module, which loads a post with id=1. This is what I need but that post is also accessible from 'forum/post/view/id/1'. That's bad, because search crawlers don't like when same page is accessible from several URLs, right?

I'm using Yii framework which supports 'useStrictParsing' option, which tells that incoming request must match at least one "pretty" route, otherwise request fails with 404. However it's not a perfect solution, because I don't have pretty URLs for every controller/action.

Ideally, framework should redirect 'forum/post/view/id/1' to 'forum/post/1' with a 301 status code. How did you solve this problem? It's not Yii/PHP specific question, how does your framework/tool deal with it?

Was it helpful?

Solution

The best way to make sure search engines only rank one page the pretty url over another, if there are multiple ways to view the content is to your a canonical tag within the header of your document

<link rel="canonical" href="http://www.mydomain.com/nice-url/" />

This is very useful with windows based system as IIS is not case sensitive with its web pages but the web standard is case sensitive.

So

  • www.maydomain.com/Newpage.aspx
  • www.maydomain.com/newpage.aspx
  • www.maydomain.com/NEWPAGE.aspx

These are all seen by Google as different pages, and you are then marked down for having a site with duplicate content, but not so with a canonical as each page in the case above would have the same canonical meta tag and the that url is the only one which will be used by the search engines.

OTHER TIPS

Provided that no one links to your non-pretty urls, the search engines will never know that they exist.

If you do want to eliminate them, you could bypass your web framework by adding an alias in you web server's configuration file; the url will be redirected before it ever reaches the framework.

Frameworks like Django, which don't provide 'magic' routing, don't face this issue, the only routes which exist are those which you define manually. In it's case, you could define a view for the non-pretty url which returns the appropriate redirect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top