How does wordpress multisite manage subdomains?

I have a WordPress multisite installed, and would like to understand how the subdomains actually are managed, ie how does my wordpress multisite knows where to find the files/data when a browser request URL user1.domain.com ?

I checked the DNS A record and see only the wild card.

I checked the .htaccess, and it looks as follows:

RewriteEngine On
RewriteBase /

# Protect the htaccess file
<Files .htaccess>
Order Allow,Deny
Deny from all
</Files>

# Protect wpconfig.php
<Files wp-config.php>
Order Allow,Deny
Deny from all
</Files>

# Disable directory browsing
Options All -Indexes

RewriteRule ^index\.php$ - [L]

# uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]

so I think the .htaccess does not manage the subdomain, or does it?

so then, how does my wordpress multisite knows where to find the files/data when a browser request URL user1.domain.com ?

1 Answer
1

During the load process, WP loads wp-settings.php, which calls is_multsite(), which checks for the multisite constant defined in wp-config.php if it is a multisite install. If it is multisite, then ms-settings.php is loaded. Inside ms-settings.php, WordPress parses the requested URI to get the domain, and calls wpmu_current_site() to set all of the current site constants based on that domain.

Leave a Comment