Sunday, November 15, 2009

Satisfy google - Create 404 error message to verify page for webmastertools

Now this was a long fight. Pew.

Quite some time ago google changes their rules for page "verification" for their webmastertools which you probably know. Now they ban the usage of redirects when a page is not found - google want's a nice "404" error message.

How does that work with liferay? By default liferay redirects all requested URLs that doen't have a corresponding page to the homepage (e.g. /web/guest/home). That's exactly what google does not like. :o/

There are now two different cases that should be distinguished:

  1. Wrong URLs "behind" the path of the homepage (e.g.
  2. Wrong URLs directly at the root path (e.g. )
(This difference has been pointed out by Chris Kauffman in the liferay forums - thanks!)

For 1) there are seetings within liferay that customize that behaviour. These work fine - but just for this use case:

For 2) This has to be adjusted on the app-server level (for my: tomcat from the bundle)

Two options:
The proper way - change the routing in the web.xml of the liferay application (in tomcat-5.5.27\webapps\ROOT\WEB-INF). There you change the entry for "error-page.

Or you do it quick and dirty :)
The "error-page" tag points to /errors/404.jsp
You can modify this file directly to turn of the redirection. That is you have to remove:
<body onload="javascript: location.replace('<%= homeURL %>')">

and related.

Now you should be friends with google again. :)


I'm happy about every feedback! :)