News
From 2 to 5 - We are relocated
20 Sep 2011 from Jeroen Bennenbroek
NGINX as an Amazon S3 authentication proxy
04 Mar 2011 from Bernd Dorn
Relaunch AZ Medien
13 Oct 2010 from Jeroen Bennenbroek
Plauderkasten VZ-networks
12 Apr 2010 from Jeroen Bennenbroek
Snow-Sprint 2010: a diverse Outcome
18 Feb 2010 from lang
Our team needs growth
13 Jan 2010 from lang
Merry Christmas and a happy 2010
23 Dec 2009 from lang
Snowsprint 2010 - Registration opened
03 Oct 2009 from Manfred Schwendinger
Lovely Systems at EuroPython 2009
30 Jun 2009 from Andreas Feuerstein
Lovely Twitter
Hacking WordPress: hide behind another apache server
22 Apr 2007 from reutz, postet in sysadmin

Howto hide a worpress instance behind a different apache server with the mod_rewrite.
I had the need to move my blog running wordpress 2.0.x to a different server, but keeping the domain name on the “old” server. I tried to do this with mod_rewrite and succeeded only partially :-(
after some hours of hacking around with mod_rewrite and wordpress itself i got i working and want to share my solution:
note: let’s call the origin server SERVER A and the “new” server running wordpress and mySQL SERVER B. SERVER A has only Apache 2 with mod_rewrite running, SERVER B has Apache, mySQL and PHP running.
Step 1: basic rewrite rules on SERVER A

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/blog/.*\.php$
RewriteCond %{REQUEST_URI} !^/blog/wp-.*
RewriteRule ^/blog(.*) http://<SERVER B>/<path to wordpress>/index.php$1 [L,P]

RewriteRule ^/blog$ http://<SERVER B>/<path to wordpress>/ [L,P]
RewriteRule ^/blog(.*)$ http://<SERVER B>/<path to wordpress>$1 [L,P]

note: my blog runs on http://<SERVER A>/blog/
Step 2: configure WordPress
login to wordpress (best done before moving wordpress to SERVER B) and go to the options -> general screen in wordpress admin and set these two values:
WordPress address (URI): http://<SERVER B>/<path to wordpress>
Blog address (URI): http://<SERVER A>/blog
Step 3: hack WordPress
now comes the part that took me hours to figure out. With all the above, wordpress almost worked, but index.php always threw a 404 not found error :-(
The problem was, that Wordpress uses $_SERVER['REQUEST_URI'] to build its links and stuff, but for my setup REQUEST_URI is <path to wordpress on SERVER B>… but this isn’t right, it should be simply /blog/…
this inserted into my config.php file does the trick:

$_SERVER['REQUEST_URI'] = str_replace(’/<path to wordpress on SERVER B>/’, ‘/blog/’, $_SERVER['REQUEST_URI']);

Step 4: there’s no step 4 ;-)

Technorati Tags: , , ,