Get rid of WP-Admin redirects

Have you ever tried to work on your local code base of WordPress using a shared database (for example the database on staging/development server) with the rest of the team?
Normally it’s not possible since WordPress stores the URL of the blog in the database and immediately redirects if the current host name doesn’t match the stored value.

Using a centralized version of the database might be useful, in particular if more developers are working on the same blog and they don’t want to replicate locally all the settings of the database in staging/dev.

Here is a plugin for that:

Plugin Name: Disable Canonical/WP-Admin URL Redirection
Description: Disables the "Canonical URL Redirect" and "WP-Admin Redirectr" features of WordPress .
Version: 1.0
Author: Guido Bellomo
Author URI:

function fake_siteurl() {
  return 'http://'.$_SERVER['HTTP_HOST'];
add_filter('pre_option_siteurl', 'fake_siteurl');
add_filter('pre_option_home', 'fake_siteurl');

Just copy and paste this in a file inside the plugin directory (for example /wp-content/plugins/disable-redirect.php).

P.S. There are similar plug that works on the redirect_canonical filter, which works for the home page, but it doesn’t for the administration panel. This plugin cheats WordPress faking the option “siteurl” and “home”.

Works nice for blogs hosted in the root directory of the domain, for blogs hosted in subdirectory additional PHP might be required in the fake_siteurl() function.
Pay attention on disable the plugin in a production environment since it could compromise the blog security.