WordPress – Wrong urls at wp-admin at wordpress with subdirectory and proxy

apache-2.2directoryPROXYredirectWordpress

I am using apache2 and mod-proxy to integrate wordpress blogs into subdirectories of my TLD.

Apach2 virtual host of the main site with proxy:

<VirtualHost *:80>
ServerName example.com

...

# Rewrite rule to add missing slashes
RewriteRule ^/blog$ /blog/ [R=301]
RewriteRule ^/other-blog$ /other-blog/ [R=301]

<Proxy *>
Order deny,allow
Allow from all
</Proxy>

ProxyRequests off
ProxyPass /blog/ http://blog1.localhost/
ProxyPassReverse /blog/ http://blog1.localhost/
ProxyPass /other-blog/ http://blog2.localhost/
ProxyPassReverse /other-blog/ http://blog2.localhost/

...

</VirtualHost>

Apach2 virtual hosts for blogs:

<VirtualHost *:80>
ServerName blog1.localhost
DocumentRoot /var/www/blog1/
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>

Linux hosts file add lines:

127.0.0.1     blog1.localhost localhost.localdomain
127.0.0.1     blog2.localhost localhost.localdomain

WordPress: Settings > General Settings:

The .htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

This setup works fine in general. Unfortunately the back end of WordPress has problems at some parts by stripping the sub-folders in URLs resulting in problems of saving settings or loading pictures. eg.:

or

What I tried so far:

Nothing of it worked so far or made it worse.

If somebody has an idea of how to solve this problem I would very much appreciate this.

*) Edit: What I already tried here:

define('WP_HOME',  'http://' . $_SERVER['HTTP_HOST'] . '/blog');
define('WP_HOME', 'http://example.com/blog');
define('WP_SITEURL', 'http://example.com' . $_SERVER['SERVER_NAME'] . '/blog');
define('WP_SITEURL', 'http://' . $_SERVER['SERVER_NAME'] . '/blog');
define('WP_SITEURL', 'http://example.com/blog/');

Best Answer

The absolute (and wrong) paths are in the content generated by WordPress - there's no way to rewrite them with Apache (how would Apache know which blog is meant when a client asks for /wp-content?).

Modifying the site URL in the WordPress config is the correct path.

For the blog1 instance:

define('WP_SITEURL', 'http://example.com/blog');

For the blog2 instance:

define('WP_SITEURL', 'http://example.com/other-blog');

What have you tried, and what behavior did you see?

Related Topic