Multisite routing guide

WordPress multisite .htaccess: subdomains vs subdirectories.

A network is not a single site with more domains. Its rewrite rules have to preserve enough path information for WordPress to identify the right site before it routes the request.

01Network mode matters.

Subdomain and subdirectory installs use similar-looking, but not interchangeable, rewrite rules.

02Keep the network block intact.

Do not replace it with the shorter single-site block when one subsite has a problem.

03Match the real base.

A network in a subdirectory needs its network setup output, not a root-install example.

Why the two network types need different rules

In a subdomain network, WordPress identifies a site primarily from the hostname: for example, shop.example.com. In a subdirectory network, the site name is part of the path: for example, example.com/shop/. Apache must leave that first path segment available to WordPress in the subdirectory case.

Network typeHow a site is identifiedRule consequence
SubdomainsThe hostname, such as shop.example.com.The rewrite block handles the usual WordPress paths without a site prefix in the request path.
SubdirectoriesThe first path segment, such as /shop/.The rules capture and pass that segment so WordPress can resolve the intended subsite.
Domain mappingThe network’s domain and site records.Do not invent rewrite exceptions first; confirm domain mapping and DNS are correct.
1 Browser requests a subsite URL2 Apache preserves the site context3 WordPress resolves the network site4 The subsite handles the page

The two network blocks, in full

Both go in the network root's .htaccess, between WordPress's own markers. Take the one that matches how your network identifies a site, whole — the lines are not interchangeable between the two.

.htaccess — multisite, subdirectories (example.com/shop/)
# BEGIN WordPress
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
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]
# END WordPress
.htaccess — multisite, subdomains (shop.example.com)
# BEGIN WordPress
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]

# 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]
# END WordPress

Neither block is wrapped in <IfModule mod_rewrite.c>, unlike the single-site block — that is how WordPress's own Network Setup screen writes them. The practical consequence is worth knowing: on a server without mod_rewrite these rules produce an outright error rather than quietly serving every subsite as the main site.

Three rules differ, and they account for the entire difference between the two topologies:

^([_0-9a-zA-Z-]+/)?wp-admin$
vs
^wp-admin$
The subdirectory version matches an optional leading site segment before wp-admin and puts it back with $1, so /shop/wp-admin redirects to /shop/wp-admin/ instead of the network's own admin.
^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*)
vs
^(wp-(content|admin|includes).*)
Core files are shared by the whole network, so the subdirectory version strips the site segment and serves the real path — the capture group shifts from $1 to $2 precisely because of that extra optional group.
^([_0-9a-zA-Z-]+/)?(.*\.php)$
vs
^(.*\.php)$
Same idea for any other PHP entry point, such as wp-login.php or xmlrpc.php, reached through a subsite path.

Copying a subdirectory rule into a subdomain network, or the reverse, is what produces the classic symptom: the main site works, and every subsite returns the main site's home page or a 404.

A network created before WordPress 3.5 may need one more rule.

Those networks served uploads through ms-files.php. If your existing block contains a line that mentions it, keep that line — replacing the block without it breaks every image on the older subsites.

Use the Network Setup output as the source of truth

WordPress generates a configuration snippet when you create a network. That output reflects the network type and installation path that Core knows about, so it should take priority over copied snippets from a different host or topology. A network that was moved into a subdirectory or changed from subdirectories to subdomains deserves a full configuration review, not a one-line rewrite edit.

Do not paste single-site rules into multisite.

The short single-site block can make the main site appear healthy while breaking subsite routes, uploads, or admin requests. Select the correct network type in the generator instead.

Repair a multisite rewrite issue in order

  1. 01
    Identify the network type.

    Look at a known subsite URL: a unique hostname means subdomains; a first path segment means subdirectories.

  2. 02
    Confirm the network root and base path.

    Find the directory containing the network’s wp-config.php. Do not assume it is the web root after a migration.

  3. 03
    Back up the current root .htaccess.

    Preserve any host, cache, HTTPS, or security directives that appear outside the WordPress network markers.

  4. 04
    Generate the matching network block.

    Choose subdomain or subdirectory in the .htaccess generator; use the Network Setup output for unusual paths.

  5. 05
    Test more than the main site.

    Open a public page and /wp-admin/ on the main site and on at least one subsite before declaring the repair complete.

Quick answers

Can I use the default single-site .htaccess rules for multisite?

No. Multisite needs its own rewrite block. Subdirectory networks in particular need rules that preserve the subsite path segment.

Do subdomain and subdirectory WordPress networks use the same rules?

No. They share a goal, but subdomain routing is based on the host name while subdirectory routing depends on the first part of the request path.

Where should a multisite .htaccess file live?

Put the network rewrite block in the WordPress network root, normally beside wp-config.php. A subsite does not usually have its own full WordPress root or its own network rewrite block.

What do the single-site rules look like, for comparison?

A single install uses a much shorter block with no site-context capture — see the default .htaccess guide. Multisite table names in the database also differ per subsite; the users-table guide covers that naming.

Primary reference: WordPress multisite administration documentation.