WordPress Multisite: Redirect Non WWW to WWW of URL

WordPress Multisite: Redirect Non WWW to WWW of URL

Since long I have been working on WordPress. Each time solving new problems teaches you new tricks. This time I stuck with redirect issue in multisite feature of WordPress where non-www version of link redirecting to mail domain. E.g. www.example.com is main domain where problem exists. If you are using WordPress & want to access subdirectory or page with example.com/xyz, you may be redirecting to www.example.com. In my case I installed subsite after www.example.com/site1, www.example.com/site2, etc. I was trying to access using example.com/site1 but it was taking me to main domain.

After lot of tries and tricks I finally found solution with below code. I just replace example.com & www.example.com is below code with my actual domain.

RewriteCond %{HTTP_HOST} ^example.com$
 RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Hope this small post is useful for you people.

1 Comment

  • This is very useful, thank you. But, it I can’t accept that htaccess rule is the solution! It seems that this ‘problem’ is mentioned many times elsewhere, and each time it’s “htaccess will fix it”, but it seems nobody knows why www. is an issue on WPMS. No explanation. I guess it must be related to subdomain. aspects of setup, but the www. issue occurs in Directory structure too. Given WPM is a CMS, why does it fail on such a rudiment requirement?

    If I install WPMS on https://www. – then this domain should be defaulted, without htaccess, should it not?

Leave a Reply

Your email address will not be published. Required fields are marked *

Show Buttons
Hide Buttons
%d bloggers like this: