Redirect the non-www version of the site to the www

In wordpress site how to Redirect the non-www version of the site to the www version to remove duplicate content

Related posts

Leave a Reply

2 comments

  1. This code is similar to Eugene’s, but it will redirect any domain that is not your main domain with “www” to the correct address. Handy if you have multiple top-level domains.

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    # These are the lines that do the trick
    RewriteCond %{HTTP_HOST} !^www.yourdomain.com$
    RewriteRule .* http://www.yourdomain.com/$0 [L,R=301]
    </IfModule>
    
  2. You need to setup it in your .htaccess file, it should looks like this one:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} ^yourdomain.com$
    RewriteRule (.*) http://www.yourdomain.com/$1 [L,R=301]
    
    RewriteRule ^index.php$ - [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>