WordPress Multisite and reverse proxy – content can not be found …
-
Hello Forum!
I have a very specific problem, looking for a hint to the solution.
This is my wordpress setup:
- Multi-blog installation in subdirectories (as different language versions of the same blogs)
- Blog-ID1 is directly on the domain http://www.xyz.de
- Blog-ID2 is on http://www.xyz.de/en/
- Blog-ID3 is on http://www.xyz.de/fr/
- …
- One database (DB on a separate server) and
- an installation (on web server).
So far everything is working properly and have been for years.
Now the reverse proxy (iF RP) comes into play.
The original URLs are rewritten by RP as follows:
- Blog-ID1 http://www.xyz.de –> http://www.abc.de/info/
- Blog-ID2 http://www.xyz.de/en/ –> http://www.abc.de/en/info/
- …
As far as this is not a problem.
The RP works and I wrote a small system-extension which is patching the corresponding $ _SERVER variables and internal links.
The RP configuration was created by my hoster and checked several times. (Managed hosting!)
With Blog-ID1 everything works fine.
With Blog-ID2,3,4,… no content is found (404).
The only exception is the internal search. Here the search results page with no results (empty).My guess: Some internal WordPress routine can not cope with the rewritten data.
My questions:
- Which routine is possible to do that?
- Do I need some more adjustments?
- Has anybody a hint for me to solve the problem?
Many thanks for your support!
Here the code of my little system-extension:
/* * # x-forwarded-host.php # * * "HTTP_X_FORWARDED_HOST" header for the duration of a single request in WordPress. * * ## Installation ## * First, put this file into the "wp-includes" folder of a WordPress installation. * Edit "wp-settings.php". Just before the call to "wp_plugin_directory_constants", * add this line: require( ABSPATH . WPINC . '/x-forwarded-host.php' ); */ define('XFH_SLUG', 'info'); // Return TRUE if this request has been forwarded. function is_forwarded() { return array_key_exists('HTTP_X_FORWARDED_HOST', $_SERVER); } // Return a short output version of get_locale(). function get_s_locale() { $localeLong = get_locale(); if ($localeLong != '') { $locale = preg_replace('@(?<=^..).*@', '', $localeLong); } else { $locale = 'en'; } return $locale; } // Patch and return 'HTTP_X_FORWARDED_HOST'. function forwarded_host() { if (is_forwarded()) { return $_SERVER['HTTP_X_FORWARDED_HOST']; } } // Patch and return 'REQUEST_URI'. function patch_request_uri() { if (is_forwarded()) { return $_SERVER['REQUEST_URI'] . XFH_SLUG . "/"; } } // Patch and return 'SCRIPT_NAME'. function patch_script_name() { if (is_forwarded()) { $locale = get_s_locale(); if ($locale == 'de') { return "/" . XFH_SLUG . $_SERVER['SCRIPT_NAME']; } else { return "/" . $locale . "/" . XFH_SLUG . $_SERVER['SCRIPT_NAME']; } } } // Patch and return 'PHP_SELF'. function patch_php_self() { if (is_forwarded()) { $locale = get_s_locale(); if ($locale == 'de') { return "/" . XFH_SLUG . $_SERVER['PHP_SELF']; } else { return "/" . $locale . "/" . XFH_SLUG . $_SERVER['PHP_SELF']; } } } /* * Create a base URL using the original "Host" header. Rather than trying to sort out * whether to use "http" or "https", just keep using whatever the scheme was for this * request. This is a good strategy when using a reverse proxy because the proxy can * handle redirecting all requests from http to https, for example. * * Also here the category slug is defined, for example "/category", in case of your * reverse proxy config. */ // Return the forwarded modified and patched URL. function forwarded_url() { if (is_forwarded()) { $host = forwarded_host(); $locale = get_s_locale(); if ($locale == 'de') { $complete = $host . "/" . XFH_SLUG . "/"; } else { $complete = $host . "/" . $locale . "/" . XFH_SLUG; } return "//$complete"; } } // Patch the "$_SERVER" superglobal, replacing the host with the forwarded host. // Some parts of wordpress (particularly "redirect_canonical") use " // $_SERVER['HTTP_HOST'],['HTTP_X_ORIG_HOST'],['REQUEST_URI'], // ['SCRIPT_NAME'],['PHP_SELF'],['REMOTE_ADDR']. function x_host_patch_server() { if (is_forwarded()) { $_SERVER['HTTP_X_ORIG_HOST'] = $_SERVER['HTTP_HOST']; $_SERVER['HTTP_HOST'] = forwarded_host(); $_SERVER['REQUEST_URI'] = patch_request_uri(); $_SERVER['SCRIPT_NAME'] = patch_script_name(); $_SERVER['PHP_SELF'] = patch_php_self(); $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR']; } } // Override the value of "home" and "siteurl". function x_host_patch_url() { if (!is_forwarded()) { return false; } return forwarded_url(); } add_filter('pre_option_home', 'x_host_patch_url'); add_filter('pre_option_siteurl', 'x_host_patch_url');
The topic ‘WordPress Multisite and reverse proxy – content can not be found …’ is closed to new replies.