• Hi,

    I am new to wordpress multisite setup in subdirectories. I am running Ubuntu 16.04 with wordpress 5.1.1.

    I installed it already and it is working, but I have not added my domains yet.

    I have 3 sites in subdirectories and I want each of these sub sites to have its own domain name.
    domain1.com (main wordpress site (wp_)
    domain2.com (1st sub directory wordpress site (wp_2)
    domain3.com (2nd sub directory wordpress site (wp_3)
    domain4.com (3rd sub directory wordpress site (wp_3)

    So I want 4 different domains (domain names) to same public IP (server) and have each domain to a different sub directory website.

    I already have the letsencrypt installed for the 4 domains as well.

    I have been looked and looked for a solution and I have not found it yet, or I don’t understand how it works:)
    So I have tried to add a domain name to one of the sites, so ones added/configured, I am not able to access it because it does not route/map correctly because of the different domain names for the URL and home directory for wp_ vs wp_2 vs wp_3 etc.

    Can someone please let me know if this is possible to accomplish? If so, how should it be configured? Any help is very much appreciated.

    Current virtual hosts file for apache2

    markus@vm-wp-16s-s1:/etc/apache2/sites-available$ cat wordpress.conf
    # Alias /wp /usr/share/wordpress
    # Alias /wp/wp-content /var/lib/wordpress/wp-content

    ServerAdmin [email protected]
    ServerName domain1.com
    ServerAlias https://www.domain1.com
    DocumentRoot /var/www/html/wordpress

    Alias /wordpress /var/www/html/wordpress
    Alias /wordpress/wp-content /var/www/html/wordpress/wp-content

    # <Directory /usr/share/wordpress>
    <Directory /var/www/html/wordpress>
    Options FollowSymLinks
    AllowOverride Limit Options FileInfo All
    DirectoryIndex index.php
    Order allow,deny
    Allow from all
    </Directory>

    <Directory /var/www/html/wordpress/wp-content>
    Options FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    </Directory>

    Current .htaccess file

    /var/www/html/wordpress/.htaccess

    RewriteEngine On
    RewriteBase /wordpress/
    RewriteRule ^index\.php$ – [L]

    # add a trailing slash to /wp-admin
    RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ – [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
    RewriteRule . index.php [L]

    Regards,
    Markus

Viewing 10 replies - 1 through 10 (of 10 total)
  • Just point the domains at the IP address of the host in DNS.

    Tell the control panel to let them in if needed.

    Tell WordPress to ‘map’ the domain to the proper subsite.

    You don’t need to manually create subdirectories for or under WordPress… those can actually break things. WordPress knows more about this subject than either of us does. Let it do its job.

    You do want to tell the CP to direct the domain at the server root where your Multisite resides if the CP needs to know about the domain.

    Just try it one at a time. If you get a directory listing (probably with a cgi-bin subdirectory) you’ll know your CP is pointing that domain at the wrong directory. Fix that. Your host should be able to help you with that also as the CP if part of their system.

    Thread Starter mhemstrom

    (@mhemstrom)

    Thank you for your reply.

    I tested to create a new site in “Network admin/Sites/Add New” and I was able to map another domain name to this sub-site and I can visit the sub-site.

    Yet, I am not able to login to the dashboard for the sub-site now. I can however login to the main site with no issues.

    I get the following error after trying to login (via web GUI) with username and password. I even created another user for this sub-site as a test. I cleared browser cache and history several times as well.

    ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.

    I did some googling and found that this might solve the issue, to add the following line in the wp-config.php file. Yet did not solve the issue.

    Tried to add

    define(‘COOKIE_DOMAIN’, false);

    And tried this

    define(‘COOKIE_DOMAIN’, $_SERVER[‘HTTP_HOST’] );

    This is part of my wp-config.php file

    define( ‘WP_DEBUG’, true );
    define( ‘WP_DEBUG_DISPLAY’, true );

    define(‘WP_ALLOW_MULTISITE’, true);

    define(‘MULTISITE’, true);
    define(‘SUBDOMAIN_INSTALL’, false);
    define(‘DOMAIN_CURRENT_SITE’, ‘xxxxx.xxxxxxx.net’);
    define(‘PATH_CURRENT_SITE’, ‘/wordpress/’);
    define(‘SITE_ID_CURRENT_SITE’, 1);
    define(‘BLOG_ID_CURRENT_SITE’, 1);

    define(‘COOKIE_DOMAIN’, false);

    Your assistance is appreciated in this matter.

    Regards,
    Markus

    Thread Starter mhemstrom

    (@mhemstrom)

    Hi,

    This solved the login issue (ERROR: Cookies are blocked) for the subsites.

    Added in wp-config.php file above “/* That’s all, stop editing! Happy blogging. */”

    define(‘ADMIN_COOKIE_PATH’, ‘/’);
    define(‘COOKIE_DOMAIN’, ”);
    define(‘COOKIEPATH’, ”);
    define(‘SITECOOKIEPATH’, ”);

    Regards,
    Markus

    Hi so your cookies will be present on any site even those external to wordpress and not only for the super administrator but also for all other users. create a site administrator for each of your sites … With the super administrator do not enter the site board or with the define $ _SERVER [‘HTTP_HOST’] login super administrator in the various sites.
    and your http_host must be an spofing anto https://expressionengine.com/blog/http-host-and-server-name-security-issues (you could expand the define prior)

    if(! empty($_SERVER['HTTP_HOST'])) {
    if($_SERVER['HTTP_HOST'] == 'www.domain1.com' || $_SERVER['HTTP_HOST'] == 'www.domain2.org' || $_SERVER['HTTP_HOST'] == 'www.domain3.en') {
    // Valid host
    define('COOKIE_DOMAIN', $_SERVER['HTTP_HOST'] );
    }
    }

    Anti spofing HTTP_HOST SERVER_NAME https://expressionengine.com/blog/http-host-and-server-name-security-issues

    In other words, given the intrinsic nature of the cookies that will be visible for the set domain, for example the first network domain https://www.domain1.com/wp-admin/network/ (dashboard network) will not be able to access different domains of domain1.com (note that the presence or absence of the www suffix is irrelevant in this context) means that the super admin can not directly access the dashboard of the sites but should access directly to the dashboard of the sites after login on the site in question https://www.domain2.org/wp-admin/network/site-info.php?id=2 (dashboard site) ie from the network administration, copy the link on the site board, then go to the site, log in and then paste the site board.
    and in this case you will not need to set the cookie because wordpress would decide to set the cookie on the current blog.
    You must set the cookie with define only in case of problems

    Thread Starter mhemstrom

    (@mhemstrom)

    Hi,

    Thank you for your reply.

    So I removed the following in wp-config.php

    define(‘ADMIN_COOKIE_PATH’, ‘/’);
    define(‘COOKIE_DOMAIN’, ”);
    define(‘COOKIEPATH’, ”);
    define(‘SITECOOKIEPATH’, ”);

    Then I created a new user for each sub-sites with administrator privileges and generated a password for each user.

    Then I went to My Sites/Network Admin/Sites and selected one sub-site and copied the URL as mentioned, in this case sub-domain with id 7

    The URL copied shows domain1 (main site) even though it is for domain3, so if I use this URL then I get the following error when I try to login with the user created for sub-domain domain3.

    Sorry, you are not allowed to edit this site.

    https://domain1.com/wordpress/wp-admin/network/site-info.php?id=7

    Then I try to modify the URL and add the correct domain name for this sub-site, like this

    https://domain3.com/wordpress/wp-admin/network/site-info.php?id=7

    Then it redirect to this and I tried to login with the sub-site user with administrator privileges, yet get the following error

    ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.

    https://domain3.com/wp-login.php?redirect_to=https%3A%2F%2Fdomain3.com%2Fwordpress%2Fwp-admin%2Fnetwork%2Fsite-info.php%3Fid%3D7&reauth=1

    What am I missing there?

    Regards,
    Markus

    in the network folder, only the super administrator can access, while all other roles are considered unreliable and therefore access as if they were not on multisite.
    This for Super Admin https://domain1.com/wordpress/wp-admin/network/site-info.php?id=7
    This for Admin for domain3 https://domain3.com/wp-admin/ (without wordpress directory).

    Thread Starter mhemstrom

    (@mhemstrom)

    Hi,

    Thank you for your reply.

    I tried https://domain3.com/wp-admin

    This is the URL I used from the very beginning of this thread for the sub-sites. When I use this URL for each sub-site, then I receive the following error as mentioned previously.

    ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.

    When this error is displayed the URL is
    https://domain3.com/wp-login.php

    Also, this is the URL when the sub-site login screen shows after entering https://domain3.com/wp-admin

    https://domain3.com/wp-login.php?redirect_to=https%3A%2F%2Fdomain3.com%2Fwordpress%2Fwp-admin%2F&reauth=1

    Is this a mapping/re-direct issue maybe?

    Regards,
    Markus

    Thread Starter mhemstrom

    (@mhemstrom)

    Hi,

    Is there anyone that can help with this issue? Or am I the only one that is using multisite with sub-sites (with different domain name).

    As mentioned above I get the following error when I try to login to the sub-sites.

    https://domain3.com/wp-admin

    ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.

    Adding this to wp-config.php solved the issue for me, but this was a security risk, so I removed it.

    define(‘ADMIN_COOKIE_PATH’, ‘/’);
    define(‘COOKIE_DOMAIN’, ”);
    define(‘COOKIEPATH’, ”);
    define(‘SITECOOKIEPATH’, ”);

    Your assistance in this matter is very much appreciated.

    Regards,
    Markus

    https://domain3.com/wp-login.php?redirect_to=https%3A%2F%2Fdomain3.com%2Fwordpress%2Fwp-admin%2F&reauth=1
    Yes this is right.
    With the variable $_SERVER[‘HTTP_HOST’] it is not safe but with the empty value in the define it is safe.

    I looked at the source code for subdirectory installations the DOMAIN_COOKIE does not seem important for the multisite subdirectory and normal installation constants but in the network.php if the www prefix is ??present. it will be expanded to the root of the domain example https://www.domain.com will be set for .domain.com (it will be visible on any subdomain) therefore it is better to set the define also with empty value.

    define( 'WP_ALLOW_MULTISITE', true );
    
    define('MULTISITE', true);
    define('SUBDOMAIN_INSTALL', false);
    define('DOMAIN_CURRENT_SITE', 'www.domain1.com');
    define('PATH_CURRENT_SITE', '/wordpress/');
    define('SITE_ID_CURRENT_SITE', 1);
    define('BLOG_ID_CURRENT_SITE', 1);
    define('COOKIEPATH','');
    define('SITECOOKIEPATH','');
    define('ADMIN_COOKIE_PATH','');
    define('COOKIE_DOMAIN','');

    The multisite creates other tables in the dababase like wp_x_options where x does not necessarily have to be an incremental number COOKIEPATH should be the home, SITECOOKIEPATH site also for non multisite installations obviously the table for the latter is wp_options. I put the empty value on ADMIN_COOKIE_PATH should be the value of SITECOOKIEPATH for multisite installations subdirectory otherwise it is SITECOOKIEPATHwp-admin.

    You have the network on the wordpress folder and this cookie should be in the wordpress folder while for mapped sites it depends on whether it is in root or other folders.I offer no guarantee on direct or indirect malfunctions, these are only reflections of these codes.
    https://github.com/WordPress/WordPress/blob/master/wp-includes/ms-default-constants.php#L50
    https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-network.php#L299
    https://github.com/WordPress/WordPress/blob/master/wp-includes/default-constants.php#L219

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Multisite (single database) in subdirectories with different domain names’ is closed to new replies.