Page 1 of 1
Redirecting www to non-www with htaccess
Posted: Fri Jan 18, 2013 11:41 pm
by PierreB
I want to redirect the www. version of the site to the non-www version
Right now I am kind of confused, because I have found SEVERAL different suggested codes to do this and I cannot evaluate which one is the best one.
I would also value the code that is valid not just for Joomla (if it can be more specific to this platform, I don't know) but other CMSs as well, like Wordpress
So, I have found the following codes.
1) This is the one provided in the Master htaccess file for Joomla
Code: Select all
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
2) Or
Code: Select all
RewriteCond %{HTTP_HOST} ^www.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]
3) Or
Code: Select all
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
4) Or
Code: Select all
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.example\.com [NC]
RewriteRule ^(.*)$ http://%1.example.com/$1 [R=301,L]
5) Or
Code: Select all
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
Which one is the most highly recommended?
Re: Redirecting www to non-www with htaccess
Posted: Sat Jan 19, 2013 6:52 am
by Yesceeohhh
I suggest this one.
RewriteBase /
RewriteCond % ^
www.example.com [NC]
RewriteRule ^(.*)$
http://example.com/$1 [L,R=301]
Re: Redirecting www to non-www with htaccess
Posted: Sat Jan 19, 2013 7:51 pm
by PierreB
Thank you for your reply @Yesceeohhh
Why would you recommend this particular one? Does it do something that others don't, you have been using it effectively etc?
Thanks...trying to understand a little bit myself
Re: Redirecting www to non-www with htaccess
Posted: Mon Jan 21, 2013 2:46 pm
by Thetjo
From what I can see all others you've mentioned should work just fine. The one recommended by Yesceeohhh seems like the one that is most clear if you ever end up checking your .htaccess file again and start wondering: "what did that setting do?"
Re: Redirecting www to non-www with htaccess
Posted: Mon Jan 21, 2013 5:02 pm
by MoonDragon
Hello,
In addition to this modification made in the .htaccess file, (for seo purpose) do not forget to make an update in google analytics in goal to merge the rank/traffic of
http://www.example.com and
http://example.com (
Process explained here.
Re: Redirecting www to non-www with htaccess
Posted: Wed Jan 23, 2013 8:26 pm
by PierreB
Thank you all for your answers...
I am principally looking about the most all-around effective rewrite code...
Several may be working, but there may be differences - pertaining to possible url configurations or cases - which may make one better than the other, more "complete" ( ? ). I don't know...
I am just supposing that if there was just a single straightforward way to do it, there wouldn't be so many different rewrite codes around for pointing www. to non-www.
I am looking for the "all-around" best, if there is such a thing...
Yes, setting the preference in google is important. I have set the preference there, I just want to make sure the redirection is doing its part as well
Re: Redirecting www to non-www with htaccess
Posted: Sat Jan 26, 2013 3:25 pm
by enrique00a
Hope you will not forget to redirect also your index page :
http://www.example.com/index.php => Redirect 301 to
http://example.com .
If your website it's made in static HTML, than you need to redirect your index.html page.
In this way you will avoid duplicate content issues, and you will have a more powerful first page!
Re: Redirecting www to non-www with htaccess
Posted: Sat Jan 26, 2013 7:18 pm
by Markstein
PierreB wrote:
I am principally looking about the most all-around effective rewrite code...
Several may be working, but there may be differences - pertaining to possible url configurations or cases - which may make one better than the other, more "complete" ( ? ). I don't know...
I am looking for the "all-around" best, if there is such a thing...
Me personally when I am looking for .htaccess redirect codes or information about them I look at posts made by a user called g1smd as he seems very knowledgeable about it. The following threads contain some code he provided to redirect non-www to www.
http://forum.joomla.org/viewtopic.php?p ... 9#p2513459
http://forum.joomla.org/viewtopic.php?p ... 2#p2491980
Make sure to read the entire threads for more information on what the code does.
Another good thread to read (though it is to force non-www to www) is:
http://forum.joomla.org/viewtopic.php?t=598832
A lot more information to read can be found by this user. Just type in a Google search the following:
site:forum.joomla.org redirect www to non-www g1smd
Or alternatively do a search for "redirect www to non-www g1smd" which will provide information on various forums.
Personally I use the code provided in one of the above links (
http://forum.joomla.org/viewtopic.php?p ... 9#p2513459) to force all non-www to www helping with Canonical URL issues.
The following is also a good video to watch on Canonicalization:
http://www.[youtube].com/watch?v=Cm9onOGTgeM
Mark
Re: Redirecting www to non-www with htaccess
Posted: Sun Jan 27, 2013 3:29 pm
by AgustA
PierreB wrote:Thank you for your reply @Yesceeohhh
Why would you recommend this particular one? Does it do something that others don't, you have been using it effectively etc?
Thanks...trying to understand a little bit myself
Hi Pierre I have done the same thing for my website . I redirect www to non www , and nothing changed . I afraid that something goes wrong ,but everything is ok .