Multisite setup help - plain domainsubsite always redirects to domain with subdir multisite

admin2025-06-04  0

I set up a path-based wp multisite using subdirs for each site. It all works well except if the subsite is accessed without www. For example -

//mainsite/subsite always redirects to //mainsite"

//www.mainsite/subsite" always redirects to //www.mainsite/subsite"

I'd like to have requests made without the www to also redirect to the subsite.

i.e //mainsite/subsite" redirect to //www.mainsite/subsite"

I've tried htaccess rules - but nothing seems to work

Rewritecond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{REQUEST_URI} ^/subsite/$1  [NC]
RewriteRule ^www.mainsite/subsite/$1 [L,R=301]

All wildcards are setup in DNS to direct to www and apache config has plain domain as the servername with alias of www.

Has anyone run across this before?

Apologies for the code - I can't post more than two http links apparently so assume anything with a // has an http: in front of it.

I set up a path-based wp multisite using subdirs for each site. It all works well except if the subsite is accessed without www. For example -

//mainsite/subsite always redirects to //mainsite"

//www.mainsite/subsite" always redirects to //www.mainsite/subsite"

I'd like to have requests made without the www to also redirect to the subsite.

i.e //mainsite/subsite" redirect to //www.mainsite/subsite"

I've tried htaccess rules - but nothing seems to work

Rewritecond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{REQUEST_URI} ^/subsite/$1  [NC]
RewriteRule ^www.mainsite/subsite/$1 [L,R=301]

All wildcards are setup in DNS to direct to www and apache config has plain domain as the servername with alias of www.

Has anyone run across this before?

Apologies for the code - I can't post more than two http links apparently so assume anything with a // has an http: in front of it.

Share Improve this question edited Jan 3, 2019 at 5:53 Danger14 2192 silver badges14 bronze badges asked Feb 13, 2016 at 8:04 user88618user88618 111 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 1

You're close.

I added a few more places to capture more scenarios and used the HTTP_HOST variable in the rule. The $1 is not needed in the condition as that would match what's captured in the above condition.

<IfModule mod_rewrite.c>
    RewriteEngine On
    Rewritecond %{HTTP_HOST} !^www\.(.*)$ [NC] 
    RewriteCond %{REQUEST_URI} ^/subsite/? [NC] 
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
</IfModule>

I recommend Made With Love's .htaccess check to verify your testing.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749049680a315925.html

最新回复(0)