How to redirect WordPress multisite non-www to www

If you would like to redirect non-www to www in WordPress multisite you are going to experience some difficulties. There are a different ways of doing it.

  • Redirect every domain (takes a lot of time)
  • Using the following code in your .htaccess (easy)

Modifying the .htaccess

Just op the .htaccess file found in the root of your server folder (or at least where the main domain is) and add this code.

RewriteEngine OnRewriteCond %{HTTP_HOST} !^www.RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Source: Dense13.com

6 comments on “How to redirect WordPress multisite non-www to www

    1. Hi, thanks for this, but I can’t get it to work with mine, I end up creating an infinite redirect loopnnI think the problem is maybe I don’t know at which point I should drop the code in the .htaccess filennI’ve tried lots of different places but none has worked so far, if you don’t mind I’ve copied my current .htaccess file below if you have any suggestions!nnCheers, NicknnnRewriteEngine OnnRewriteBase /nRewriteRule ^index.php$ – [L]nn# uploaded filesnRewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]nnRewriteCond %{REQUEST_FILENAME} -f [OR]nRewriteCond %{REQUEST_FILENAME} -dnRewriteRule ^ – [L]nRewriteRule . index.php [L]

      1. RewriteEngine OnnRewriteBase /nRewriteRule ^index.php$ – [L]nRewriteCond %{HTTP_HOST} !^www.nRewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]nn# uploaded filesnRewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]nnRewriteCond %{REQUEST_FILENAME} -f [OR]nRewriteCond %{REQUEST_FILENAME} -dnRewriteRule ^ – [L]nRewriteRule . index.php [L]nnbut make sure your host also has the .www as default otherwise there will be an infinte redirection loop.

        1. I ended up needing to change a bunch of values in the MySQL database. I am using Multi Site and although I could see things were being redirected, the site wasn’t being found due to the URL in the DB being set to domain.com (and not http://www.domain.com).nnMaybe I didn’t set this correctly when I first installed multi site WP, but now I have changed those values all seems to be working.nnJust thought I’d mention it in case someone else has to do a similar thing.

Leave a Reply

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