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.com/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.

1 Answer 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]

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

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.