1

So, this is the situation. I have a working top level domain site (https://example.com) and I set up a wild card subdomain (*.example.com) and multisite settings in WordPress. It works as expected, as in if I go to network and create a new site (e.g. https://b2b.example.com), it does that. However, when I check the settings for that new site under Site > edit, instead of using the subdomain URL, it uses the top level domain URL. If I then manually correct this, I am still being redirected (e.g. https://b2b.example.com/wp-admin keeps being redirected to the top level wp-admin page). I also noticed that when I manually correct the URL to b2b.example.com and I visit /wp-admin it goes back to example.com.

I suspect this has to do with my .htaccess, but I'm not very sure of it, so any help is welcome. The site is redirected from http to https for all domains, including the wildcard sub domains.

Here is (part of) my .htaccess:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\Comodo\DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/.+$
RewriteRule ^(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>

#Rewrite http to https
RewriteEngine On
RewriteCond %{HTTPS} !=on [NC]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
Header always set Content-Security-Policy "upgrade-insecure-requests;"

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress

Can anyone give me some advice?

1
  • "I suspect this has to do with my .htaccess" - FWIW, there's nothing in the .htaccess file you've posted that would cause this behaviour. Check the X-Redirect-By HTTP response header on the initial (redirect) response - this may give you a clue as to what is triggering the redirect.
    – MrWhite
    Nov 6, 2023 at 13:15

1 Answer 1

1

Take a look at your wp-config.php file. For a subdomain installation, you should have something like this:

define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', 'rareteas.com');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

If you have SUBDOMAIN_INSTALL set to false, change it to true, which is necessary for a subdomain multisite.

Next, take a look at your database. Sometimes URLs get written directly into the tables and don’t want to leave without a bit of coaxing. Access your database via phpMyAdmin or similar and check the wp_site, wp_blogs, wp_options (for each site, the table might be wp_2_options, wp_3_options, etc.), and wp_sitemeta tables. Make sure the URLs are correct and reflect the subdomain structure you’re aiming for.

And if you're using domain mapping or have any domain redirect plugins, it's worth disabling them temporarily to see if it alleviate the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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