Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

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

this has not redirect the www site to non-www site. please any help me.

share|improve this question
Usually I use DNS redirection to do that – Simon Mar 30 '12 at 7:06
hello simon, how to do the DNs redirection? – ayyan Mar 30 '12 at 7:09
Using WPSE search I've found the solution for you. – Max Yudin Mar 30 '12 at 7:15
hai maxoud, i try that solution but it not works. – ayyan Mar 30 '12 at 7:19
Connect to your hosting provider, managing your domain, and search for option redirection (choose permanent redirection so search engines will update their database). This way, the URL could be changed before even hitting the http server, no charge added to the server, I find it more simple. – Simon Mar 30 '12 at 12:03

closed as off topic by toscho Aug 19 '12 at 14:23

Questions on WordPress Answers are expected to relate to WordPress within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

2 Answers

It would help use to know how exactly is your solution or the one Maxoud mentioned not working? Is it just not redirecting? Is there something in the error logs?

In some cases it does cause problems when you are already on a sub-domain to do htaccess rewriting.

What worked for me in those cases was creating two virtual hosts that are the same except for the ServerName (where one is with and one without www) and the path they are pointing to. Then just put your content in the path you want (in your case the one that got pointed from the ServerName with www) and but this htaccess inside the root of the other path:

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http:www\.//demo\.yourdomain\.com/$1 [R=301,L]

Then it should work. Don't forget to restart apache though ;)

share|improve this answer

Take a look at the html5boilerplate .htcaccess file and you'll find a lot of useful tasks including help for your problem: https://github.com/h5bp/html5-boilerplate/blob/master/.htaccess

This might help too: http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html?m=1

share|improve this answer
That is an interesting collection of examples, thanks for the link. But it also states: Be aware that the following rule might not be a good idea if you use "real" subdomains for certain parts of your website. I am guessing with "real" they mean non-www subdomains, which is the case for ayyan. – tim Mar 30 '12 at 8:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.