non www to www htaccess

Discuss Search Engine Optimization in relation to Joomla! 3.x. This forum will also have discussions on SEF/SEO Joomla! 3.x 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.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
tinboye
Joomla! Apprentice
Joomla! Apprentice
Posts: 21
Joined: Sat Dec 26, 2009 10:30 pm

non www to www htaccess

Post by tinboye » Mon Mar 13, 2017 3:25 am

So I am running latest version of joomla, and trying to get redirect to work
I have SANs SSL with godaddy,
so www.mysite.com is set for the https://
when I type mysite.com in the browser it goes to https://mysite.com
and then i get the error about invalid certificate.

I need it to redirect automatically to https://www.mysite.com

I have tried the above

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

I have tried

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}$1

and

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule .* https://%1%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule .* https://%1%{REQUEST_URI} [R=301,L]


none of which will work.

anyone have any further suggestions?

User avatar
ranwilli
Joomla! Master
Joomla! Master
Posts: 19203
Joined: Sun Feb 19, 2006 6:47 pm
Location: Toledo, OH
Contact:

Re: non www to www htaccess

Post by ranwilli » Mon Mar 13, 2017 4:53 am

Don't HACK the Joomla! core, Instead "Extend" and/or "Override."
Stay ON the update path.
https://harpervance.com

tinboye
Joomla! Apprentice
Joomla! Apprentice
Posts: 21
Joined: Sat Dec 26, 2009 10:30 pm

Re: non www to www htaccess

Post by tinboye » Mon Mar 13, 2017 5:07 am

I appreciate the reply. I have followed this and my domain does in fact always show https:// whether its with or without www.
my problem is that in firefox browser
I type domain.com
then it loads https://domain.com
which is not covered under the SSL, but the https://www.domain.com is
so i get the error:
http://i.imgur.com/TxBYw7d.png

I need to force the browser to redirect non-www to www for that domain. the tutorials I have tried, none of them work. I am using a SANs SSL through godaddy.

User avatar
ribo
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3507
Joined: Sun Jan 03, 2010 8:47 pm
Contact:

Re: non www to www htaccess

Post by ribo » Mon Mar 13, 2017 6:54 am

The non www to www redirect will not fix the invalid ssl to a valid ssl. First you must configure fine your ssl from your host control panel. Ask your host about that.
chat room spontes : http://www.spontes.com

tinboye
Joomla! Apprentice
Joomla! Apprentice
Posts: 21
Joined: Sat Dec 26, 2009 10:30 pm

Re: non www to www htaccess

Post by tinboye » Mon Mar 13, 2017 1:16 pm

The SANS SSL only allows so many entries it is not a wildcard SSL. I should not have to create an entry for both www and non www . I have read many pages that a person can simply force a redirect. I've done it in the past in ht access. But something with joomlas rewrite rules does not allow it in Firefox.

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 44094
Joined: Sat Apr 05, 2008 9:58 pm

Re: non www to www htaccess

Post by Webdongle » Mon Mar 13, 2017 1:38 pm

ribo wrote:The non www to www redirect will not fix the invalid ssl to a valid ssl. First you must configure fine your ssl from your host control panel. Ask your host about that.
It's my understanding that the cert is correctly setup because https://www.hissite.com does not throw the error. It's the lack of www that means the https://hissite.com doesn't match the www.hissite.com on the cert.

Simple fix ... in the .htaccess in the Joomla root under

Code: Select all

## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
add

Code: Select all

########## Begin - Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
## If the above throws an HTTP 500 error, swap [R=301,L] with [R,L]
########## End - Redirect non-www to www
Thanks to Leo for providing me with that code


N.B.
It's for .htaccess on Linux servers
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".

User avatar
ribo
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3507
Joined: Sun Jan 03, 2010 8:47 pm
Contact:

Re: non www to www htaccess

Post by ribo » Mon Mar 13, 2017 1:55 pm

The same can work with the code

Code: Select all

RewriteCond %{HTTP_HOST} !^www\.mysite\.com
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
and this work for non ssl sites and for ssl sites if you force ssl in joomla config, but i saw in the screen that OP provides that his ssl is like a self signed cert, so i thought that maybe something in his ssl config is his host control panel is missing. For example if in SAN's ssl cert must increase the number of sites, or something else?
chat room spontes : http://www.spontes.com

tinboye
Joomla! Apprentice
Joomla! Apprentice
Posts: 21
Joined: Sat Dec 26, 2009 10:30 pm

Re: non www to www htaccess

Post by tinboye » Mon Mar 13, 2017 2:41 pm

In joomla backend I force SSL on entire site. As soon as I type mysite.com in Firefox address bar and hit enter. It goes to https://mysite.com Instead of https://www.mysite.com. Google always seems to goto www. Automatically. So maybe a bug in Firefox?

tinboye
Joomla! Apprentice
Joomla! Apprentice
Posts: 21
Joined: Sat Dec 26, 2009 10:30 pm

Re: non www to www htaccess

Post by tinboye » Mon Mar 13, 2017 4:27 pm

here is my htaccess file

http://pastebin.com/0EcmU1Ti

still does not redirect non-www. to www.

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 44094
Joined: Sat Apr 05, 2008 9:58 pm

Re: non www to www htaccess

Post by Webdongle » Mon Mar 13, 2017 5:32 pm

tinboye wrote:In joomla backend I force SSL on entire site. As soon as I type mysite.com in Firefox address bar and hit enter. It goes to https://mysite.com Instead of https://www.mysite.com. Google always seems to goto www. Automatically. So maybe a bug in Firefox?
If www is not included in the address bar when calling the site then www will not be included in the adress bar when the site is reached (unless the server is configured to prefix the domain name with www). The code that I gave you works with Joomla set to 'force' ssl.

Forcing ssl (changing http to https) is totally independent to whether or not www is in the address.

www (or non www) is how the browser finds the site

https refers to the protocol (language) that the browser and server use once the browser find the site.

Imagine that you are delivering a parcel to 'Fred Blogs, Cherry Tree Lane' ... some people might prefix it with 'Mr' others might not ... but you still deliver it. When you ask him to sign for the parcel you speak in the language defined on your docket. The language you speak to him in has nothing to do with how you navigated to his house.

The code I gave you makes sure (in the above scenario) that 'Mr' (www) is always written before 'Fred Blogs' and has no relationship to the language (https) you use when speaking to him.
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".

tinboye
Joomla! Apprentice
Joomla! Apprentice
Posts: 21
Joined: Sat Dec 26, 2009 10:30 pm

Re: non www to www htaccess

Post by tinboye » Mon Mar 13, 2017 5:56 pm

i know when i had a dedicated server, i was able to go into httpd and make it so non-www would always go to www. but being with godaddy, i do not have that option, i even tried a redirect of mysite.com to www.mysite.com 301 perm
and even that does not work.

I know there has to be a way to force the browser to go to www. all the time for a specific domain. I just have to figure out how to do that with godaddy.
https works just fine, it always uses https regardless.
whether I use the htaccess or not, I can leave the default joomla htaccess file alone, and just set force ssl in backend of joomla and it will always use https.

at this point I guess I just have to make a another ssl certificate for mysite.com and have the 2 SANs 1 with and 1 without www

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 44094
Joined: Sat Apr 05, 2008 9:58 pm

Re: non www to www htaccess

Post by Webdongle » Mon Mar 13, 2017 8:26 pm

tinboye wrote:i know when i had a dedicated server, i was able to go into httpd and make it so non-www would always go to www. but being with godaddy, i do not have that option...
I have already told you how to redirect non www to www
Webdongle wrote: ... in the .htaccess in the Joomla root under

Code: Select all

## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
add

Code: Select all

########## Begin - Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
## If the above throws an HTTP 500 error, swap [R=301,L] with [R,L]
########## End - Redirect non-www to www
Thanks to Leo for providing me with that code


N.B.
It's for .htaccess on Linux server
s
It is a Linux server ... yes ?

Make sure you have not given a value to the $live_site var in configuration.php

btw
Gddy sometimes cache the .htaccess. So edits made to .htaccess may not show up for some time.
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".

tinboye
Joomla! Apprentice
Joomla! Apprentice
Posts: 21
Joined: Sat Dec 26, 2009 10:30 pm

Re: non www to www htaccess

Post by tinboye » Mon Mar 13, 2017 11:48 pm

i had to reissue the SSL and then it allowed the redirect to work.

ramjay
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Tue Aug 22, 2017 12:56 am

Re: non www to www htaccess

Post by ramjay » Thu Feb 08, 2018 10:42 pm

Hi Tinboye,
Could you please explain the fix, which redirect did you end up using?
In what order (if it matters) did you do things.
Do you force ssl in joomla first etc

Thanks

ramjay
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Tue Aug 22, 2017 12:56 am

Re: non www to www htaccess

Post by ramjay » Thu Feb 08, 2018 10:43 pm

Also, where to place the code in the .htaccess file? an image/screenshot would be helpful.

Thanks

sozzled
I've been banned!
Posts: 13639
Joined: Sun Jul 05, 2009 3:30 am
Location: Canberra, Australia

Re: non www to www htaccess

Post by sozzled » Thu Feb 08, 2018 10:59 pm

ramjay wrote:Also, where to place the code in the .htaccess file? an image/screenshot would be helpful.
See @Webdongle's two posts written less than a year ago. ;)

ramjay
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Tue Aug 22, 2017 12:56 am

Re: non www to www htaccess

Post by ramjay » Tue Feb 13, 2018 11:07 pm

Thanks Sozz and all of the above,

I have the same ssl package from Godaddy, but I need the opposite of Tinboye.
My ssl works fine with this url: https://medicalcannabis.com.au/
But if I add www into the equation I get the following message:

Your connection is not secure

The owner of www.medicalcannabis.com.au has configured their website improperly. To protect your information from being stolen, Firefox has not connected to this website.


I went to joomla meetup last night and was suggested the following code:

RewriteCond %{HTTP_HOST} ^www\. [OR]

RewriteCond %{HTTPS} off

RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$

RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R]

which produces the following analytics.

Warning!

This website uses a temporary (HTTP 302) redirect from http://www.medicalcannabis.com.au to http://medicalcannabis.com.au. This is OK, but a permanent (HTTP 301) redirect is considered best practice. Close recommendations

If possible, change the temporary redirect to a permanent (HTTP 301) redirect.




The code Leo/Webdongle suggested is set up to redirect "non www to www"
I need to 301 redirect www to non-www

And do I need to redirect http to https ?

ramjay
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Tue Aug 22, 2017 12:56 am

Re: non www to www htaccess

Post by ramjay » Wed Feb 14, 2018 9:56 pm

Add these lines of code to your .htaccess directly below the type: RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\. [OR]

RewriteCond %{HTTPS} off

RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$

RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]



See example below.


RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\. [OR]

RewriteCond %{HTTPS} off

RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$

RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]


I uploaded the amended .htaccess file to GoDaddy and it worked immediately, no caching or delay.

The above fixed my ongoing issue of my Godaddy Sans SSL (up to 5 domain names)
not directing a www. url to the https:// secure server.

Hope this helps others.

I obtained this code from the Joomla meetup in Sydney and Tim Plummer, big thanks to Tim.


Locked

Return to “Search Engine Optimization (Joomla! SEO) in Joomla! 3.x”