Skip to content

Instantly share code, notes, and snippets.

@ljfauscett
Created October 24, 2012 17:26
Show Gist options
  • Save ljfauscett/3947494 to your computer and use it in GitHub Desktop.
Save ljfauscett/3947494 to your computer and use it in GitHub Desktop.
Allows wordpress be accessed with via X-Forwarded-Host servername.
<?php
/*
Plugin Name: Forwarded Host Support
Description: Allows the blog to be accessed with via X-Forwarded-Host servername.
Author: blahed
Version: 0.0.1
Author URI: http://forwardhq.com/
*/
function has_forwarded_host() {
return array_key_exists('HTTP_X_FORWARDED_HOST', $_SERVER);
}
function forwarded_host() {
return $_SERVER['HTTP_X_FORWARDED_HOST'];
}
function forwarded_base() {
$_forwarded_host = forwarded_host();
return "//$_forwarded_host";
}
function apply_forwarded_host() {
if ( !has_forwarded_host() )
return false;
return forwarded_base();
}
function replace_with_forwarded_host($url, $path = '') {
if ( !has_forwarded_host() )
return $url;
else
return preg_replace('!https?://[a-z0-9.-]*!', '//' . forwarded_host(), $url);
}
add_filter('pre_option_home', 'apply_forwarded_host');
add_filter('pre_option_siteurl', 'apply_forwarded_host');
add_filter('pre_option_url', 'apply_forwarded_host');
add_filter('stylesheet_uri', 'replace_with_forwarded_host');
add_filter('admin_url', 'replace_with_forwarded_host');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment