Use Case:

I am setting up wordpress for one of my clients. The wordpress is setup at a domain like http://cms.domainA.com. This domain is on VPN which can only be accessed by using VPN and few additional software. To make the wordpress accessible from the main website there are proxies are created such that https://cms.domainB.com pointing to http://cms.domainA.com.
https://cms.domainB.com is publicily accessible.

What I want here is wordpress to load normally with all wp-admin, login functionality, post creation etc working from https://cms.domainB.com also.

Here is the nginx configuration:

server_name  cms.domainB.com;

        location / {
                 proxy_pass http://stg-traefik;
                 proxy_set_header Host "cms.domainA.com";
                 proxy_http_version 1.1;
                 proxy_set_header Connection "";
                 proxy_set_header X-Forwarded-Proto $scheme;
                 add_header X-Frame-Options "DENY" always;
                 add_header X-Content-Type-Options "nosniff" always;
                 add_header X-XSS-Protection "1; mode=block" always;
                 add_header strict-transport-security "max-age=31536000; includeSubDomains; preload" always;

This nginx is verified and works well for other node and react projects needing similar approach.

W.r.t wordpress, all the script, css urls in the page are absolute urls due to which it tries to access resource from http://cms.domainA.com when opening https://cms.domainB.com and fails. I have tried other approaches also to update wordpress address url and site address url from wordpress page, wp config etc but they are not of any help.

The only solution which seems to be partially working is modify esc_url function in wp-includes/formatting.php to return relative url but for that, I would have to manually modify the functionality in the wordpress core which I don't want to do. All the urls accessible from cms.domainA.com are also opening from cms.domainB.com if I copy paste them in new tab. The issue is that wordpress while generating html; makes all urls absolute.

Current HTML structure (when loading https://cms.domainB.com)

Observe here, all urls are absolute so even though proxies are correct -> as cms.domainA.com is behind VPN, it doesn't work properly. enter image description here

Partial Possible working solution (when loading https://cms.domainB.com)

Observer here, most urls are relative so they load well with a lot of functionality working well. This is the current approach I am working on. enter image description here

Is there a way to make all urls relative to install location or Is there a way to update absolute urls based on from where request is coming or Is there a third better way that can be used here?

Any help will be highly appreciated. Let me know if there are any further clarifications needed.

Edit: One thing I missed adding here is that wordpress is multisite setup here.

  • so you want domain mapping but you don't want WP to fix canonical URLs? And you want all domainA.com URLs to have domainB.com when accessed via domainB?
    – Tom J Nowell
    Nov 29 '21 at 22:22
  • If WP can fix canonical URLs that will be great (I don't think it will be major issue as site won't be indexed/crawled from domainA.com it being on VPN). But main requirement is to have domain updated when accessed from domainB.com as domainA isn't available without VPN and hence breaks a lot of functionality related to login, post creation, admin operations Nov 30 '21 at 6:11
  • WP will redirect do domainA as that's the canonical URL. If the same content is available on both it will give an SEO penalty for duplication
    – Tom J Nowell
    Nov 30 '21 at 9:38
  • WP will redirect do domainA as that's the canonical URL - Can this be avoided? SEO penalty I understood but domainA will never be crawled or visible to external world. It's the domainB which will be visible to external world -> So, if redirection happens from B to A; that is also problematic as domainA won't load. And hence I want to use domainB by modifying urls or using relative urls Nov 30 '21 at 9:46
  • are you sure it wouldn't be easier to use domain B for everything and prevent access to WP Admin for users who aren't on the VPN? It would dramatically simplify things and avoid a lot of potential issues
    – Tom J Nowell
    Nov 30 '21 at 10:17

Your Answer

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

Browse other questions tagged or ask your own question.