Redirecting www to non-www with htaccess

Discuss Search Engine Optimization in relation to Joomla! 2.5. This forum will also have discussions on SEF/SEO Joomla! 2.5 extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
PierreB
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 152
Joined: Tue Sep 21, 2010 2:39 pm

Redirecting www to non-www with htaccess

Post by PierreB » Fri Jan 18, 2013 11:41 pm

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?

User avatar
Yesceeohhh
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 159
Joined: Mon May 14, 2012 9:56 am
Location: Irving, TX 75039
Contact:

Re: Redirecting www to non-www with htaccess

Post by Yesceeohhh » Sat Jan 19, 2013 6:52 am

I suggest this one.

RewriteBase /
RewriteCond % ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

PierreB
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 152
Joined: Tue Sep 21, 2010 2:39 pm

Re: Redirecting www to non-www with htaccess

Post by PierreB » Sat Jan 19, 2013 7:51 pm

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

Thetjo
Joomla! Explorer
Joomla! Explorer
Posts: 499
Joined: Fri Nov 13, 2009 1:33 pm
Contact:

Re: Redirecting www to non-www with htaccess

Post by Thetjo » Mon Jan 21, 2013 2:46 pm

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?"
http://www.conversionreview.com/ - Start improving your conversion rate with an expert review

MoonDragon
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 231
Joined: Sat Oct 15, 2011 4:05 pm

Re: Redirecting www to non-www with htaccess

Post by MoonDragon » Mon Jan 21, 2013 5:02 pm

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.

PierreB
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 152
Joined: Tue Sep 21, 2010 2:39 pm

Re: Redirecting www to non-www with htaccess

Post by PierreB » Wed Jan 23, 2013 8:26 pm

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

enrique00a
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Sat Aug 06, 2011 8:52 am
Location: Bucharest / Romania
Contact:

Re: Redirecting www to non-www with htaccess

Post by enrique00a » Sat Jan 26, 2013 3:25 pm

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!
Mai scriu pe blog https://emrzone.ro despre design si optimizare CMS-uri diverse.

Markstein
Joomla! Hero
Joomla! Hero
Posts: 2268
Joined: Sat Feb 09, 2008 8:27 am
Location: California, USA

Re: Redirecting www to non-www with htaccess

Post by Markstein » Sat Jan 26, 2013 7:18 pm

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

AgustA
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Thu Oct 18, 2012 2:30 pm
Location: Paris
Contact:

Re: Redirecting www to non-www with htaccess

Post by AgustA » Sun Jan 27, 2013 3:29 pm

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 .


Locked

Return to “Search Engine Optimization (Joomla! SEO) in Joomla! 2.5”