$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Multisite setup help - plain domainsubsite always redirects to domain with subdir multisite|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin10PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far