- Home
- Blogs
- George Boobyer's blog
- handling 404 errors on hosted CMS
handling 404 errors on hosted CMS
A general housekeeping task for CMS systems such as Wordpress and Drupal and other websites and good practice to keep your site SEO high is to make sure you are gracefully handling missing pages (404 errors).
One of the routine tasks to carryout is checking for crawl errors in Google Webmaster tools. If you see any missing pages in the list it is worth making sure you have some measures in place to handle these and ideally issue a 301 redirect so that Google and other search engines update their indexes.
On Linux based systems we have the mod-rewrite module to help out here and I have written a lot about using rewrites in the .htaccess and http.conf to manage redirects for missing pages.
But what if you are using a managed hosting account on a Windows server? No mod-rewrite module and no chance of getting a 3rd party filter like IsapiRewrite installed.
There are a number of options depending on your hosting provider.
1) metarefresh - The simplest least ideal way
You can create a standard redirect file for each missing file with a meta refresh in it such as:
<html> <head> <meta http-equiv="refresh" content="0;URL=/index.php"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>exampledomain.com - Page Moved</title> </head> <body> <p>This page has moved - if you don't get redirected - please <a href="/index.php">click here</a></p> </body> </html>
This will issue a 200 page found response and redirect the client to the Wordpress / Drupal (or other CMS) home page.
2) Response header method - The better way
The above solution doesn't really cut it as all you have done is to cancel the 404 response replacing it with a 200 response page redirect..
Ideally you should issue a 301 Permanently moved response so Google et al stop trying to get to the missing page.
So if you have PHP or asp.net running you can use the following to augment the above solution.
<?php header('HTTP/1.1 301 Moved Permanently'); header('Location: http://'.$_SERVER['HTTP_HOST']); exit() ; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="refresh" content="0;URL=/index.php"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>exampledomain.com - Page Moved</title> </head> <body> <p>This page has moved - if you don't get redirected - please <a href="/index.php">click here</a></p> </body> </html>
.. and if you are using C# / asp.net on your host
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" %> <script runat="server"> private void Page_Load(object sender, System.EventArgs e) { string strqry = "http://" + Request.ServerVariables["HTTP_HOST"] + "/index.aspx" ; Response.Status = "301 Moved Permanently"; Response.AddHeader("Location",strqry); } </script> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="refresh" content="0;URL=/index.php"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>exampledomain.com - Page Moved</title> </head> <body> <p>This page has moved - if you don't get redirected - please <a href="/index.aspx">click here</a></p> </body> </html>
These use server side code (PHP / C#) issue a 301 redirect and if that fails falls back on the metarefresh method
So now we have a redirect.php of redirect.aspx file to use as a template for any missing pages.
But that is still hands on and repetitive to keep copying the file for every missing page
Some (most?) hosts provide a mechanism to use a custom file for error pages such as 404.
In many cases this will actually provide a 200 response but present a 'Page not found page'
A 200 response to a missing page is less than ideal - Google webmaster tools for example checks to see if your site issues 404 responses for missing page - it does this by requesting a page that won't exist on your site. So ideally you should naturally return 404 errors for missing pages and 301 for pages that have moved.
So a good tip is to point your custom errors for 404 to the redirect.php file and that way all of your 404s will be automatically handled as 301 responses.
What about if you are getting 404s in Wordpress.
i.e. /index.php/some-renamed-post-entry
The above method will not work as the page (index.php) is found and then Wordpress issues a 404 internally.
So here we can call on a great plugin Redirection form http://urbangiraffe.com/ - plugin home page: http://wordpress.org/extend/plugins/redirection/
This provides internal word press redirect handling and is invaluable for managing your redirects within Word press.
In Drupal you have the excellent global redirect module to achieve the same.
Contact Details
Blue-Bag Ltd
- info [at] blue-bag.com
- Telephone: 0843 2894522
- Blue-Bag HQ:
The Garage, Manor Farm
Chilcompton, Radstock
Somerset, BA3 4HP, United Kingdom - Telephone: (+44) 01761 411542
- Blue-Bag Brighton:
Unit 35 Level 6 North, New England House
New England Street, Brighton
BN1 4GH United Kingdom - Telephone: (+44) 07944 938204
- VAT GB 748125034
- UK Company Reg: 3932829