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.

  • 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 "<Proxy *> is not needed for reverse proxies, you can get rid of it. – ezra-s 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? – Liliane 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) – ezra-s 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). – Liliane 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. – ezra-s Mar 28 '18 at 15:38
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.