• Resolved grega2

    (@grega2)


    We have WP multisite network with WooCoomerce shops. All the network is served through Cloudflare CDN.

    Our ERP is accessing WooCommerce API of each website in the WP network. Since there so many, calls we are getting 503 from Cloudflare. It’s not a server problem. It’s a problem of too many requests to Cloudflare.

    So what I would like to have is a separated subdomain (example: api.domain.com) for each domain in the network. That subdomain will not be proxied thru Cloudflare.

    Exaple:
    I have sites:
    – domain1.com
    – domain2.net
    – domain3.org

    All those domains are proxied thru cloudflare CDN. To each of this sites I would like to add subdomain API which will not be proxied thru Cloudflare. So if you visit domain1.com or api.domain1.com it should be exactly the same website.

    How to do I do that? How can I add an additional subdomain to a site on WP multisite network?

    • This topic was modified 2 years, 7 months ago by James Huff. Reason: moved to Networking WordPress since this is a multisite question
Viewing 9 replies - 1 through 9 (of 9 total)
  • All those domains are proxied thru cloudflare CDN. To each of this sites I would like to add subdomain API which will not be proxied thru Cloudflare. So if you visit domain1.com or api.domain1.com it should be exactly the same website.

    How to do I do that? How can I add an additional subdomain to a site on WP multisite network?

    What you need to do is modify your DNS records.

    I.) domain1.com will remain as a CNAME record that points to Cloudflare servers.

    II.) create a new api.domain1.com record with A type that points to your own machine.

    III.) Then, you’ll need to modify your web server config for a new virtual host with the same root directory as the directory of your WordPress.

    If all these sounds too complicated/confusing for you, you’ll need to contact your sys admin / developer to do this for you.

    Thread Starter grega2

    (@grega2)

    Hi,

    I know all about how to do that… But the problem is we are having WordPress Multisite network. I do not know how to attach additional subdomain to each site of the network. Thats the main problem since API needs to be called thru the appropriate domain…

    But the problem is we are having WordPress Multisite network. I do not know how to attach additional subdomain to each site of the network.

    Perhaps I could be missing details in your setup, but this is what I think.

    The API subdomain simply act as a mirror.

    A site in a multisite network exist either as sub-domain or sub-directory:
    https://www.ads-software.com/support/article/create-a-network/
    https://www.ads-software.com/support/article/before-you-create-a-network/

    sub-domain based: site1.example.com , site2.example.com

    sub-directory based: example.com/site1 , example.com/site2

    I.) For either sub-domain or sub-directory based, create an A type DNS record for api.site1.example.com and point it to the IP of your machine.

    II.) Configure vhost:

    If sub-domain based:
    add api.site1.example.com to your existing site1.example.com vhost config , so they both share the same config

    If sub-directory based:
    create a new vhost config for api.site1.example.com and have the home directory set to example.com/site1

    Thread Starter grega2

    (@grega2)

    Yes api subdomain act as a mirror. But you have to tell WP that api.domain1.com is a mirror for domain1.com. This is the main problem – i do not know how to do that.

    If I add api subdomain to server it redirects you to “master” domain.

    When you go to api.domain1.com it redirects you to masterdomain.com/wp-signup.php?new=api.domain1.com. But api.domain1.com should be a mirror of domain1.com.

    1.)

    When you go to api.domain1.com it redirects you to masterdomain.com/wp-signup.php?new=api.domain1.com.

    This means the http request for api.domain1.com is being properly directed to the WP home directory, but WP does not recognize the domain corresponding to any existing site under WP multisite.

    Hence, WP redirects the user to wp-signup.php?new=api.domain1.com URL to prompt the user for signing up a new WP site for the unrecognized domain under WP multisite.

    However, we don’t want to sign up a new site under WP multisite for the domain, we only want the new domain to be a mirror of an existing site.

    2.)

    I.)
    Go to Network Admin -> Settings -> Under “Registration Settings”, set “Allow new registrations” to “Registration is disabled”

    II.)
    In your wp-config.php , add the following:

    define(‘NOBLOGREDIRECT’, ‘https://’ . $_SERVER[‘HTTP_HOST’] . ‘/path/to/wordpress’);

    III.)
    Then, you need to set WP_SITEURL and WP_HOME constant.

    In your wp-config.php , add/edit the following:

    define(‘WP_SITEURL’, ‘https://’ . $_SERVER[‘HTTP_HOST’] . ‘/path/to/wordpress’);
    define(‘WP_HOME’, ‘https://’ . $_SERVER[‘HTTP_HOST’] . ‘/path/to/wordpress’);

    This makes your WP_SITEURL and WP_HOME dynamic to whichever domain is being used to visit the webserver.

    There is one drawback to this method, though, the URLs in blog content won’t get reflected. I assume this shouldn’t be an issue since you simply want an additional api subdomain to query the same site.

    Hence, I would suggest you try this method first.

    3.)
    If the above doesn’t work or you want your secondary domain to act as a full site as your primary site, that is, including the URLs in the blog content reflecting the domains being used.

    You may need to use a plug-in by searching “multiple domains” in the plug-in directory:
    https://www.ads-software.com/plugins/search/multiple+domains/

    =====

    note: replace &#8217[semicolon] above with a closing single quote

    Thread Starter grega2

    (@grega2)

    This steps (1,2) are not helpful… They cannot be working since you would need to tell WP which site to load, but you dont. Its just handles redirects.

    Ill check plugins, but Iam sure that there has to be a simple code solution to that.

    I would only need to tell WP which site to load if the url cannot be matched with any existing blogs/sites….

    How are you doing with the plug-in method? Were you able to eventually solve your problem?

    If you’ve been able to solve your issues, it’s a good practice to mark this topic as “Resolved” per forum guidelines.

    You can do this using the “Status” drop-down menu located on the right sidebar of this page.

    In addition, this can help out other users.

    Thanks.

    Thread Starter grega2

    (@grega2)

    I have resovled it myself.

    I have enabled sunrise in wp-config. Then add a script to sunrise.php to override HTTP_HOST.

    I made it dynamic since we have many websites. When you visit api.domainxy.com it automatically shows you domainxy.com.

    
    $re = '/(?:api\.)(.*)/m';
    $str = $_SERVER['HTTP_HOST'];
    
    preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
    
    if ($matches && $matches[0][1] != "") {
      $_SERVER['HTTP_HOST'] = $matches[0][1];
    }
    
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘WP Multisite – Additional subdomain on each site for API purposes’ is closed to new replies.