Follow @besz
If you are as excited as we are about WordPress 3.1 bringing out Multisite with full force, you may be wondering whether it requires a lot of setup to create a network of sites for all your WordPress sites.
One thing we ourselves noticed is that WordPress did not offer any option to redirect any calls to specific directories or files on the main network domain site to either its www or non-www counterpart.
That is a big issue for many.
The Issue
If you install WordPress 3.1 with Multisite enabled on your main site with the domain http://domain.com without the www part, then typing in http://www.domain.com/directory/ would result in you being redirected to http://domain.com , instead of the intended http://domain.com/directory/ directory.
The exact opposite for redirecting a non-www to the www counterpart has the same issue for the main domain on your Multisite.
That means your main network domain, which is the site you install WordPress 3.1 with Multisite on, will not be automatically redirecting to the www or the non-www versions if you get any links or calls to the version you did not specify in WordPress.
WordPress, however, automatically redirects any subdomain sites you add to your main domain network to their exact www or non-www versions without any problems.
Adding redirect code to your .htaccess does not seem to work for majority of the people using Multisite when it comes to the main network domain redirections.
Any redirect code people are adding or already have in their .htaccess file for their main network domain seems to be not working.
Here is the solution to fix all that.
The Solution
Social Improve has the solution for you that works easily on any host that allows you to edit your .htaccess files. Any redirect code you use for your main network site in any regular htaccess works with WordPress Multisite under one condition: you must put it on top of your .htaccess file before anything else. Basically, WordPress Multisite htaccess commands at the top take preference over any commands that follow, so you must put your redirect code at the very top of your .htaccess file above any WordPress Multisite commands. WordPress Multisite htaccess commands also actually specify how to redirect domains, so you will want to put either of the two code snippets below at the very top of your .htaccess file.
Here are the two versions of the code to put at the very top, above anything else, in your .htaccess file, depending on whether you want www or the non-www version as the end result of any calls to any links on your domain.
Redirect any non-www calls to www for your main WordPress Multisite domain
RewriteEngine On
RewriteCond %{HTTP_HOST} ^socialimprove.com$ [NC]
RewriteRule ^(.*)$ http://www.socialimprove.com/$1 [R=301,L]
Replace the word “socialimprove” twice above to your own domain name.
Redirect any www calls to non-www links for your main WordPress Multisite domain
RewriteEngine On
RewriteCond %{HTTP_HOST} !^socialimprove.com.com$
RewriteRule (.*) http://socialimprove.com/$1 [R=301,L]
Once again, replace the word “socialimprove” twice in the above code.
That’s it!
Good luck with your Multisite! Please let us know if you have any questions or comments via your comments below. Thanks.
Follow @besz







thanks dude its working i have done its on my site
Awesome, glad it worked!
Thank You Soooooooooooo Much! I was just going to disable the Multisite option and this just helped.
Thanks
Hi Kirk,
Awesome to hear that! What kind of a Multisite option do you have, and are you going from WWW to non-www or vice versa?
Seriously, thank you. I was sure solving this problem would take me a few days at least. Props to Social Improve!
Thanks Kyle!
Glad this helped.
Thanks you so much, it was real easy to redirect from non-www to my main site by using your code