Resolved : WordPress Multisite Non-www Redirects All to Home Page

Hello guys, I set up this site to share the solution to some of the problem/experience using WordPress. Recently I installed WordPress multisite , all was going fine until  I noticed that Non-www Redirects back to the Home Page.
Imagine typing adovat.com/wordpress and then it redirects back to www.adovat.com. Quite frustrating especially the  negative effect on my website  SEO.

I searched through tons of articles online but all of them were saying the same thing.

Add the code to your .htaccess file if you want to redirect non-www to www

# BEGIN NON-WWW REDIRECT TO WWW
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,NC]
# END NON-WWW REDIRECT TO WWW

If you want www redirecting to non www, add this to your .htaccess:

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

None of these worked until I came across a comment on really-simple-ssl.com/ on the same topic,
In most cases, you simply need to  add any of the code to the top on your .htaccess. Like the example below

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

</IfModule>

# END WordPress

If it doesn’t work, try adding “rewrite engine on” before the code

Share with us if this worked for you

Leave a Reply

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