2

I have a site e.g. example.wordpress.com (a subsite wordpress multisite) but I want users to see the content of that site under a different domain e.g. cooking.com. I have A record setup for both domains to forward to same IP, and I have read that if I want to keep domain name in the URL that I need to use mod_proxy. This is my setup:

<VirtualHost *:80>
    ServerName cooking.com

    ProxyRequests Off
    <Proxy *>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Proxy>
    ProxyPass / http://example.wordpress.com/
    ProxyPassReverse / http://example.wordpress.com/
</VirtualHost>

However, when I type cooking.com in my browser, it redirects me to example.wordpress.com and displays its URL instead of cooking.com. What's wrong with my apache file?

I have also tried using mod_rewrite instead, but I still get the same result:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^cooking.com$ [NC]
RewriteRule ^(.*)$ http://example.wordpress.com/$1 [L,P,NC]

I have enabled mod_proxy and mod_proxy_http, and I'm using Apache 2.4 on Ubuntu 16.04.

Gitnik
  • 147
  • 2
  • 9
  • there is nothing wrong with what you show, the problem lies somwhere else. Examine the Location headers sent in the redirect replies including the scheme. Note " is not needed for reverse proxies, you can get rid of it. – Daniel Ferradal Mar 28 '18 at 15:21
  • @ezra-s Location in response headers for `301` redirect reads: `https://example.wordpress.com`, can it be that `.htaccess` and virtualhost of `example.wordpress.com` (https redirection - although I am not forcing HTTPS in any conf file) are messing with this? – Gitnik Mar 28 '18 at 15:26
  • Perfect, then you are missing another proxypassreverse that includes the same thing you have but with https (you can add as many proxypassreverse as necessary to catch all cases) – Daniel Ferradal Mar 28 '18 at 15:31
  • @ezra-s thanks ezra :) But if I add `ProxyPassReverse / https://example.wordpress.com/` for some reason the sites redirects to itself in infinite loop (i.e. Location header is cooking.com in response, and it just redirects itself). – Gitnik Mar 28 '18 at 15:36
  • Alright, try with "ProxyPreserveHost on" so you send the backend the same host the client is requesting, if wordpress allows it perhaps it won't repeatedly try to redirect to the other domain. Consider it is possible you need to validate the external domain in your wordpress (in its control panel or whatever) instalation for the same purpose. – Daniel Ferradal Mar 28 '18 at 15:38
  • @ezra-s Nothing really happens when I add this. i.e. page is loading and loading and loading, but nothing is loading, and page is not displayed. I have to see with superiors whether the wordpress can change that options. I'm not admin of the site, just the server. – Gitnik Mar 28 '18 at 15:44
  • IIRC wordpress has fields where you must fill their authorizative domain/s otherwise this kind of bahaviuour can be expected. – Daniel Ferradal Mar 28 '18 at 15:45
  • Thanks @ezra-s I will look into it. There is a way to change multisite url from wordpress itself, but I was hoping I could put it behind a reverse proxy. – Gitnik Mar 28 '18 at 15:52

1 Answers1

1

I've resolved the issue. For reasons unknown to me original site was forcing HTTPS (although I didn't configure it). As user ezra-s suggested (upon examining the Location in response headers) I have changed ProxyPassReverse to redirect to HTTPS domain (which lead into infinite loop). However, upon examining the apache logs, and googling, the solution was to add SSLProxyEngine on. It works now, and it redirects to the site but without changing URL in the browser.

Note for beginners like me

You can look at response headers in the developers console in your browser, just go to the network tab, and (re)load the page.

Note for wordpress multisite users

Although the domain for subsite is changed, site still contains links to it's pages addressed to the old domain.

Gitnik
  • 147
  • 2
  • 9