Redirect WordPress site from Apache to another Apache

Alles, was den Apache betrifft, kann hier besprochen werden.

Redirect WordPress site from Apache to another Apache

Postby GroundLoop » 16. April 2020 22:10

Have an Apache install on our main webserver that needs to redirect all traffic for http://www.mydomain.com to another Apache server that is hosting a WordPress site. The main page renders but all nested pages show the local ip address of the hosting server instead of the domain name (ex. 192.168.2.5:81/aboutus/). I have done this before redirecting to an IIS site and it works.

The VirtutalHost on the main webserver looks like this:

<VirtualHost 192.168.2.4:80>
ServerAdmin me@gmail.com
ServerName www.mydomain.com
ServerAlias mydomain.com
ProxyRequests Off

<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost On
ProxyPass /wodpresssite/ http://192.168.2.5:81/wodpresssite/
ProxyPassReverse /wodpresssite/ http://192.168.2.5:81/wodpresssite/
ProxyPass / http://192.168.2.5:81/wodpresssite/
ProxyPassReverse / http://192.168.2.5:81/wodpresssite/
</VirtualHost>


VirtualHost on other server that hosts new WordPress site:
local ip address of this machine is 192.168.2.5

<VirtualHost *:81>
ServerName wordpresssite
DocumentRoot "c:/wamp64/www/wordpresssite"
<Directory "c:/wamp64/www/wordpresssite/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Allow from all
Require all granted
</Directory>
</VirtualHost>
GroundLoop
 
Posts: 3
Joined: 16. April 2020 22:02
XAMPP version: WAMP
Operating System: Windows 10

Re: Redirect WordPress site from Apache to another Apache

Postby Nobbie » 17. April 2020 11:21

The easiest fix is to modify your WordPress configuration:

Edit wp-config.php on the WordPress Server, search for "192.168.2.5:81" and replace by "www.mydomain.com". As you changed the HTTP Port from 80 to 81 on the WordPress machine (what is NOT recommended), WordPress does not run anymore directly on that machine, only as reverse proxy. One of the many problems when changing the default ports. If you configure your frontend Apache also to listen to Port 81 (as well as your VirtualHosts), you may leave the Port number in the substitution. But i recommend not to do so, instead run Apache HTTP on Port 80 an nothing else.

If you dont like that fix, you may INSTEAD substitute the IP in the response body at runtime in the frontend Apache. If you are running Apache 2.4 or newer, you can use mod_substitute for that, see https://httpd.apache.org/docs/2.4/mod/m ... itute.html

Code: Select all
AddOutputFilterByType SUBSTITUTE text/html
Substitute "s/192.168.2.5:81/www.mydomain.com/n"


If you do not have mod_substitute, you finally may use mod_proxy_html to modify the links as needed. See https://httpd.apache.org/docs/2.4/mod/m ... _html.html
Substitute the IP by the domain via:

Code: Select all
ProxyHTMLInterp On
ProxyHTMLURLMap /192.168.2.5:81/ /www.mydomain.com/
Nobbie
 
Posts: 13176
Joined: 09. March 2008 13:04

Re: Redirect WordPress site from Apache to another Apache

Postby GroundLoop » 17. April 2020 17:23

Thanks for the reply. Took your advise and moved Apache to port 80. Since the install was new I just clobbered it, reinstalled, and reloaded the website. Now if I type in 192.168.5/wordpressite on the local machine it redirects to localhost/wordpressite and the pages render correctly. If I type in www.mydomain.com on the local machine it renders the page but changes the address to localhost/wordpresssite and the pages render correctly.
If I type in www.mydomain on another computer it of course redirects to localhost/wordpressite and fails. So there is a consistent redirect to localhost/wordpresssite

If I just type in 192.168.2.5 from another computer http://192.168.2.5/ renders and the wamp server page renders.

BTW, I did not see any occurrence of 192.168.2.5:81 in the wp-config.php file

So now I have:

VirtualHost on front end server:

<VirtualHost 192.168.2.4:80>
ServerAdmin me@gmail.com
ServerName www.mydomain.com
ServerAlias mydomain.com
ProxyRequests Off

<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost On
ProxyPass /wodpresssite/ http://192.168.2.5/wodpresssite/
ProxyPassReverse /wodpresssite/ http://192.168.2.5/wodpresssite/
ProxyPass / http://192.168.2.5/wodpresssite/
ProxyPassReverse / http://192.168.2.5/wodpresssite/
</VirtualHost>


VirtualHost on other server that hosts new WordPress site:
local ip address of this machine is 192.168.2.5

<VirtualHost *:80>
ServerName wordpresssite
DocumentRoot "c:/wamp64/www/wordpresssite"
<Directory "c:/wamp64/www/wordpresssite/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Allow from all
Require all granted
</Directory>
</VirtualHost>
GroundLoop
 
Posts: 3
Joined: 16. April 2020 22:02
XAMPP version: WAMP
Operating System: Windows 10

Re: Redirect WordPress site from Apache to another Apache

Postby Nobbie » 17. April 2020 18:07

GroundLoop wrote:BTW, I did not see any occurrence of 192.168.2.5:81 in the wp-config.php file


If you reinstalled everything, you probably have "localhost", or "wordpresssite" as Server. Anyway, simply watch out for the servername in wp-config.php

You may also struggle with browser cache. So which links are generated NOW (after reinstalling WordPress) in your reverse proxy? All my advices are still valid, its on you to find out which links are generated by WordPress.
Nobbie
 
Posts: 13176
Joined: 09. March 2008 13:04

Re: Redirect WordPress site from Apache to another Apache

Postby GroundLoop » 17. April 2020 19:37

Nobbie wrote:If you reinstalled everything, you probably have "localhost", or "wordpresssite" as Server
In which file?
The wp-config.php does not the word "server" in it. It does have define( 'DB_HOST', 'localhost' ); but that's for MySQL
GroundLoop
 
Posts: 3
Joined: 16. April 2020 22:02
XAMPP version: WAMP
Operating System: Windows 10

Re: Redirect WordPress site from Apache to another Apache

Postby Nobbie » 17. April 2020 19:47

Sorry, i am not a WordPress Expert, i read a lot about wp-config.php and i am pretty sure, that there is a kind of server or domain or URL or whatever that leads to the actual URL. As this is not a WordPress Forum, i cannot help any further, if you have no idea how to configure WordPress, you actually should go for a WordPress forum.
Nobbie
 
Posts: 13176
Joined: 09. March 2008 13:04

Re: Redirect WordPress site from Apache to another Apache

Postby Altrea » 17. April 2020 20:07

There are multiple places a WordPress url can be defined and changed. Maybe this will help: https://kinsta.com/knowledgebase/change-wordpress-url/
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11934
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Redirect WordPress site from Apache to another Apache

Postby Nobbie » 17. April 2020 20:10

Last not least - if you cannot change WordPress and the generated URLs, simply use fix number 2 oder number 3. I showed 3 different ways how to fix the problem (see above).
Nobbie
 
Posts: 13176
Joined: 09. March 2008 13:04

Re: Redirect WordPress site from Apache to another Apache

Postby secretgarden4112 » 06. May 2020 19:14

GroundLoop wrote:Thanks for the reply. Took your advise and moved Apache to port 80. Since the install was new I just clobbered it, reinstalled, and reloaded the website. Now if I type in 192.168.5/wordpressite on the local machine it redirects to localhost/wordpressite and the pages render correctly. If I type in www.mydomain.com on the local machine it renders the page but changes the address to localhost/wordpresssite and the pages render correctly.
If I type in www.mydomain on another computer it of course redirects to localhost/wordpressite and fails. So there is a consistent redirect to localhost/wordpresssite

If I just type in 192.168.2.5 from another computer http://192.168.2.5/ renders and the wamp server page renders.

BTW, I did not see any occurrence of 192.168.2.5:81 in the wp-config.php file

So now I have:

VirtualHost on front end server:

<VirtualHost 192.168.2.4:80>
ServerAdmin me@gmail.com
ServerName www.mydomain.com
ServerAlias mydomain.com
ProxyRequests Off

<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost On
ProxyPass /wodpresssite/ http://192.168.2.5/wodpresssite/
ProxyPassReverse /wodpresssite/ http://192.168.2.5/wodpresssite/
ProxyPass / http://192.168.2.5/wodpresssite/
ProxyPassReverse / http://192.168.2.5/wodpresssite/
</VirtualHost>


VirtualHost on other server that hosts new WordPress site:
local ip address of this machine is 192.168.2.5

<VirtualHost *:80>
ServerName wordpresssite
DocumentRoot "c:/wamp64/www/wordpresssite"
<Directory "c:/wamp64/www/wordpresssite/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Allow from all
Require all granted
</Directory>
</VirtualHost>


Did you ever sort this out? I have a similar issue and already attempted the other fixes discussed..
secretgarden4112
 
Posts: 2
Joined: 06. May 2020 19:10
XAMPP version: 7.2.30
Operating System: Linux


Return to Apache

Who is online

Users browsing this forum: No registered users and 163 guests