Redirect non www to www

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
haralake
Joomla! Apprentice
Joomla! Apprentice
Posts: 25
Joined: Mon Jan 23, 2012 11:18 am

Redirect non www to www

Post by haralake » Mon Jan 23, 2012 11:40 am

I want to redirect all my URL's with non www to URL's with www. I put redirect 301 code into .htaccess of my domain but all i get is to redirect only my main page. (ex. mysite.com redirect to www.mysite.com) . When i enter other URL's nothing happen. (ex. mysite.com/services/ is not redirecting to www.mysite.com/services/) .What can i do to redirect every single page of my site with www in front? Is there any plugin extension for that problem?

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 11119
Joined: Thu Feb 15, 2007 5:48 am
Location: Oxford, UK

Re: Redirect non www to www

Post by toivo » Mon Jan 23, 2012 12:41 pm

Try this:

Code: Select all

#### redirect example.com to http://www.example.com ####
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
The $1 entry copies the rest of the request to the rewritten URL.
Toivo Talikka, Global Moderator
troubleshooting smtp and other articles http://talikka.com/joomla

haralake
Joomla! Apprentice
Joomla! Apprentice
Posts: 25
Joined: Mon Jan 23, 2012 11:18 am

Re: Redirect non www to www

Post by haralake » Mon Jan 23, 2012 1:05 pm

I put that code in .htaccess and the same thing happen...
My site is indexed with www.example.com and with example.com. When someone enters to my main page example.com everything is ok because it redirect him to www.example.com. But if someone enters for ex. example.com/services/ from google then all the browsing in my site is without www. That is because the redirect 301 is only for the main page (example.com)???

I enter sites without that problem and when i change the url from www.example.com/something/ to example.com/something/ and hit enter, it redirects to www.example.com/something/. How they do that??

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 11119
Joined: Thu Feb 15, 2007 5:48 am
Location: Oxford, UK

Re: Redirect non www to www

Post by toivo » Mon Jan 23, 2012 7:29 pm

The code I listed works for me and others, too: http://www.thesitewizard.com/apache/red ... main.shtml
Toivo Talikka, Global Moderator
troubleshooting smtp and other articles http://talikka.com/joomla

lethal0r
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Mon Jan 16, 2012 2:18 pm
Location: Lancaster
Contact:

Re: Redirect non www to www

Post by lethal0r » Mon Jan 30, 2012 10:43 am

perhaps there is another htaccess file in a subdirectory?

haralake
Joomla! Apprentice
Joomla! Apprentice
Posts: 25
Joined: Mon Jan 23, 2012 11:18 am

Re: Redirect non www to www

Post by haralake » Mon Jan 30, 2012 12:01 pm

Ok, the problem solved. I was putting the code after joomla codes in .htaccess file. I put the code in the right place and everything is ok. Thanks.

User avatar
brunoalec
Joomla! Apprentice
Joomla! Apprentice
Posts: 31
Joined: Tue Sep 02, 2008 5:49 pm
Location: Rio - Brasil
Contact:

Re: Redirect non www to www

Post by brunoalec » Fri Feb 03, 2012 1:05 pm

Hi Haralake, can you share the code you used to solve your problem please ?
with best regards
Bruno Alecrim
Bruno Alecrim
Rio - Belem - Brasil
http://www.unicasite.com

haralake
Joomla! Apprentice
Joomla! Apprentice
Posts: 25
Joined: Mon Jan 23, 2012 11:18 am

Re: Redirect non www to www

Post by haralake » Fri Feb 03, 2012 1:22 pm

You must put this code before joomla codes in .htaccess

RewriteEngine On

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

g1smd
Joomla! Guru
Joomla! Guru
Posts: 951
Joined: Mon Feb 21, 2011 4:02 pm
Location: UK

Re: Redirect non www to www

Post by g1smd » Sun Feb 05, 2012 10:37 pm

The above code does not redirect all non-canonical URLs.

Try this:

Code: Select all

RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
See also: http://forum.joomla.org/viewtopic.php?t=598832
Online since 1995.

g1smd
Joomla! Guru
Joomla! Guru
Posts: 951
Joined: Mon Feb 21, 2011 4:02 pm
Location: UK

Re: Redirect non www to www

Post by g1smd » Fri Feb 10, 2012 9:28 am

Unfortunately the code linked to by toivo has limited use.

For a site at www.example.com the code redirects requests for example.com but fails to redirect requests for www.example.com:80 [port], example.com:80 [port], www.example.com. [period], example.com. [period], www.example.com.:80 [period and port], and example.com.:80 [period and port], all of which are valid alternative hostnames and all of which pose the same duplicate content problem.
Online since 1995.

User avatar
brunoalec
Joomla! Apprentice
Joomla! Apprentice
Posts: 31
Joined: Tue Sep 02, 2008 5:49 pm
Location: Rio - Brasil
Contact:

Re: Redirect non www to www

Post by brunoalec » Fri Feb 10, 2012 1:51 pm

Newbie question:

1 - Where should I insert the code ? In the beginning, botton or anywhere inside the .htaccess file?

2 - Doing that I dont need to worry about this issue, or should I do something more, like using any plugin ?

PS: Sorry about my bad english writing.

With best regards
Bruno Alecrim
Rio - Belem - Brasil
http://www.unicasite.com

g1smd
Joomla! Guru
Joomla! Guru
Posts: 951
Joined: Mon Feb 21, 2011 4:02 pm
Location: UK

Re: Redirect non www to www

Post by g1smd » Sat Feb 11, 2012 2:37 am

Make sure you have the latest version of the htaccess file. If you're using an old version of Joomla make sure you get a new htaccess file from the latest Joomla installer.

There's a section in the new htaccess file that explains where any redirect should go. In general it goes after all code that blocks malicious requests and it must go before any code which internally rewrites any request.
Online since 1995.

shenlong
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Tue Feb 14, 2012 4:44 am

Re: Redirect non www to www

Post by shenlong » Tue Feb 14, 2012 7:35 am

Using a 301 redirect on the “non-www” version of the URL, which is essentially a “permanent” redirect in server talk, you can effectively consolidate all of your link popularity to a single URL. This consolidation will serve to increase your website’s chances of obtaining and maintaining top rankings.

Read more: How to 301 Redirect Non-WWW to WWW URLs | StepForth Web Marketing Inc.
Under Creative Commons License: Attribution

g1smd
Joomla! Guru
Joomla! Guru
Posts: 951
Joined: Mon Feb 21, 2011 4:02 pm
Location: UK

Re: Redirect non www to www

Post by g1smd » Tue Feb 14, 2012 8:08 pm

... or use the code in the post just a little bit back up this page.
Online since 1995.

sburm
Joomla! Apprentice
Joomla! Apprentice
Posts: 30
Joined: Mon Oct 11, 2010 5:57 am

Re: Redirect non www to www

Post by sburm » Wed Aug 29, 2012 7:27 am

I am trying a new free host and they don't seem to give access to .htaccess so I would like to know, as per the original question, if anyone knows of an extension that does this?

karlosdpm
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Thu Nov 15, 2012 7:57 am

Re: Redirect non www to www

Post by karlosdpm » Thu Nov 15, 2012 8:00 am

What .htaccess file are you altering? Make sure you alter the .htaccess file in the root of your old website. This article might be helpfull for you: http://www.kmbytes.com/blog/redirect-to ... -redirect/

User avatar
Obir
Joomla! Apprentice
Joomla! Apprentice
Posts: 45
Joined: Wed Jun 03, 2009 4:10 pm
Location: Honolulu, HI
Contact:

Re: Redirect non www to www

Post by Obir » Thu Nov 15, 2012 8:29 pm

Thanks for this post. I was placing the code in the wrong .htaccess file and in the wrong place within the file. I placed this into the root .htaccess before the joomla code and it worked perfectly. Thanks again.

WeaveKing
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Thu Nov 15, 2012 8:50 pm
Location: Houston
Contact:

Re: Redirect non www to www

Post by WeaveKing » Thu Nov 15, 2012 8:55 pm

Thanks for this info, I will try this with my .htaccess file.

g1smd
Joomla! Guru
Joomla! Guru
Posts: 951
Joined: Mon Feb 21, 2011 4:02 pm
Location: UK

Re: Redirect non www to www

Post by g1smd » Thu Nov 15, 2012 11:14 pm

The non-www to www redirect does NOT "go before the Joomla code".

It goes somewhere in the middle of the Joomla code, specifically in the place where it mentions to "insert redirects here".

Make sure you have the latest version of the htaccess file. Even if you are continuing to use an old version of Joomla, make sure you get the latest version of the Joomla htaccess file from the latest Joomla installer.

This file explains exactly where the redirects should go.
Online since 1995.

User avatar
changlee
Joomla! Explorer
Joomla! Explorer
Posts: 380
Joined: Tue Nov 20, 2007 11:05 am
Location: Greece
Contact:

Re: Redirect non www to www

Post by changlee » Mon Dec 02, 2013 11:56 am

toivo wrote:Try this:

Code: Select all

#### redirect example.com to http://www.example.com ####
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
The $1 entry copies the rest of the request to the rewritten URL.
I added this code to the last part of my .htaccess

It works perfect but I face one small bug:

For example, if you click the url http://www.blb.gr/seo-websites it works perfect, but if you remove the www. and click it (http://blb.gr/seo-websites), it redirects to http://www.blb.gr/index.php

What else have we to do?
If you do not programm your life, someone else will do it for you.
FREE SMTP Newsletter at: https://www.emailbat.com Free and low cost Templates at: https://www.b2b-templates.com

bobsisf
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Fri Dec 06, 2013 5:43 pm

Re: Redirect non www to www

Post by bobsisf » Fri Dec 06, 2013 5:52 pm

changlee wrote:
toivo wrote: It works perfect but I face one small bug:

For example, if you click the url http://www.blb.gr/seo-websites it works perfect, but if you remove the www. and click it (http://blb.gr/seo-websites), it redirects to http://www.blb.gr/index.php

What else have we to do?
remove $ from: ^example\.com$

Try this way:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

User avatar
changlee
Joomla! Explorer
Joomla! Explorer
Posts: 380
Joined: Tue Nov 20, 2007 11:05 am
Location: Greece
Contact:

Re: Redirect non www to www

Post by changlee » Sat Feb 21, 2015 11:58 am

That was great.

What have I to do in order to redirect more than one parked domain for the same website?

To copy the same code for each domain?

Eg

Code: Select all

#### redirect example.com to http://www.example.com ####
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

Code: Select all

#### redirect otherdomain.com to http://www.otherdomain.com ####
RewriteCond %{HTTP_HOST} ^otherdomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.otherdomain.com/$1 [R=301,L]
Thanks again
If you do not programm your life, someone else will do it for you.
FREE SMTP Newsletter at: https://www.emailbat.com Free and low cost Templates at: https://www.b2b-templates.com

nickal
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Thu Jan 29, 2015 12:02 pm
Location: Piraeus, Greece
Contact:

Re: Redirect non www to www

Post by nickal » Thu Mar 12, 2015 5:03 pm

I am also using three domains for my website :)

What exactly have I to set in .htaccess ?

hulkjoshua
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Fri Mar 13, 2015 8:06 am
Location: South Africa
Contact:

Re: Redirect non www to www

Post by hulkjoshua » Sat Mar 14, 2015 4:05 am

what is the seo value of redirecting www version of the site to non www version of the site for the rest of the pages except the home page. i figured that if u go to google webmaster tools and in site settings u tell google which version of ur site u want then thats all u need to do

User avatar
changlee
Joomla! Explorer
Joomla! Explorer
Posts: 380
Joined: Tue Nov 20, 2007 11:05 am
Location: Greece
Contact:

Re: Redirect non www to www

Post by changlee » Mon Mar 16, 2015 10:07 am

I use two domains for my website and I need the .httacces to redirect ONLY to www.domain1.com and www.domain2.com

Not to domain1.com and domain2.com
If you do not programm your life, someone else will do it for you.
FREE SMTP Newsletter at: https://www.emailbat.com Free and low cost Templates at: https://www.b2b-templates.com

nickal
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Thu Jan 29, 2015 12:02 pm
Location: Piraeus, Greece
Contact:

Re: Redirect non www to www

Post by nickal » Wed Apr 08, 2015 10:12 am

Anyone about that fix?

User avatar
changlee
Joomla! Explorer
Joomla! Explorer
Posts: 380
Joined: Tue Nov 20, 2007 11:05 am
Location: Greece
Contact:

Re: Redirect non www to www

Post by changlee » Thu May 07, 2015 9:40 am

Is anyone here that has used that NON www. for more than two domains in same website?

:eek:
If you do not programm your life, someone else will do it for you.
FREE SMTP Newsletter at: https://www.emailbat.com Free and low cost Templates at: https://www.b2b-templates.com

mbc1
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Sun May 10, 2015 1:45 pm
Contact:

Re: Redirect non www to www

Post by mbc1 » Sun May 10, 2015 1:51 pm

Thanks for this info, I will try this with my .htaccess file.



-----------------------------
http://dirtv.jimdo.com/

User avatar
changlee
Joomla! Explorer
Joomla! Explorer
Posts: 380
Joined: Tue Nov 20, 2007 11:05 am
Location: Greece
Contact:

Re: Redirect non www to www

Post by changlee » Thu May 21, 2015 1:57 pm

Did you tried for two domains also?
If you do not programm your life, someone else will do it for you.
FREE SMTP Newsletter at: https://www.emailbat.com Free and low cost Templates at: https://www.b2b-templates.com


Locked

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