Page 2 of 2

Re: How to redirect the non-www address to the www

Posted: Thu Jan 05, 2012 8:32 pm
by alirm
Hi guys.

I think I have a complicated problem.
here is a scenario:

I have one hosting account on and two domains ( one is .com and another is .net).
I have assigned the root folder to my .com domain and it is obviously joomla.
My second domain (.net) is a simple HTML website that I have placed it on a new folder in the root(sub folder). = for my .com joomla website = Placed on a new folder on same host ( folder name is example1)

Case: I have redirected my .com from non-www to www using htaccess file and it works great.
The PROBLEM is when visitors clicking on my .net website then it redirects them to the .com and it shows the root folder not my .net domain name?!!!!(
I have removed the redirect www and then I can see my .net domain name again.(
So, somehow these commands conflicted on my .net and .com domains and when I turned on redirect www then I will loose my .net URL and vice versa.

Would you please let me know how I can use www redirect for my .com and also have my in the same time?


Re: How to redirect the non-www address to the www

Posted: Sat Jan 28, 2012 10:30 am
by alforrest
As a newbie site builder I found this thread very useful. I had been advised to use a Redirect PHP file but found that using .htaccess works much better. Also had issues because I keep the main site within a subfolder in Public_html incase I want to include subdomains. kept geting a Forbidden 403 issues until I moved .htaccess up from Mydomain folder to public_html will this likely cause problem in the future if I build other sites in this domain?

Re: How to redirect the non-www address to the www

Posted: Fri Feb 03, 2012 5:23 pm
by AnguyenESP
Hey everyone,

I know this has been asked countless times but I can't seem to get the redirect to work. Here is what is in my htaccess file. Please help thank you.

# @version $Id: htaccess.txt 20196 2011-01-09 02:40:25Z ian $
# @package Joomla
# @copyright Copyright (C) 2005 - 2011 Open Source Matters. All rights reserved.
# @license GNU General Public License version 2 or later; see LICENSE.txt

# The line just below this section: 'Options +FollowSymLinks' may cause problems
# with some server configurations. It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that dissallows changing it in
# your .htaccess file. If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url's. If they work,
# it has been set by your server administrator and you do not need it set here.

## Can be commented out if causes errors, see notes above.
Options +FollowSymLinks

## Mod_rewrite in use.

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]
## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site block out the operations listed below
# This attempts to block the most common type of exploit `attempts` to Joomla!
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
## End - Rewrite rules to block out some common exploits.

# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).

# RewriteBase /

## Begin - Joomla! core SEF Section.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/component/) [OR]
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
## End - Joomla! core SEF Section.

Re: How to redirect the non-www address to the www

Posted: Sun Feb 05, 2012 10:42 pm
by g1smd
Your htaccess file is very old and has many problems built in.

Make sure you get a new copy from the latest version of the Joomla installer.

You should use the new copy of htaccess even if you are using an old version of Joomla.

The new file fixes a number of problems as well as showing exactly where in the file any additional redirects should go.

Re: How to redirect the non-www address to the www

Posted: Tue Nov 06, 2012 1:13 pm
by omdeapes
dhuelsmann wrote:Place it immediately after

Code: Select all

RewriteEngine On
But you may also want to check whether your rewrite is working -
Let's test to see if mod_rewrite is enabled on your server. Place only the following code in .htaccess:

Code: Select all

RewriteEngine On
Options +FollowSymLinks
Redirect /google.html
Now point your browser to:
If it redirects you to Google - mod_rewrite is working.
If it gives you an error - mod_rewrite is not working.

Note: Replace "" with your actual web site domain.

Thank you" dhuelsmann "! This worked good for me

Re: How to redirect the non-www address to the www

Posted: Sat Oct 22, 2016 10:08 am
by mpikkis
I have the same problem kinda.My domain is if anyone wants to see my problem in action. I have a .htaccess redirection which works ok, but the request url ALWAYS gets lost, eg. i try and it redirects to Thats what i want. BUT if i try it redirects me to and NOT dont want subdomains redirected, and that works also
My .htaccess

Code: Select all

RewriteCond %{HTTP_HOST} !^(.*)\.(.*)\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I have tried this

Code: Select all

RewriteCond %{HTTPS} off
RewriteCond %{HTTPS} on
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
And it does everything i wanted to do EXCEPT redirect non-www to www

Any help appreciated !

Re: How to redirect the non-www address to the www

Posted: Sat Oct 22, 2016 10:21 am
by mpikkis
I finally got it. You should put the code ABOVE joomla sef config, right after RewriteEngine On

Re: How to redirect the non-www address to the www

Posted: Fri Mar 10, 2017 11:04 pm
by tinboye
So I am running latest version of joomla, and trying to get redirect to work
I have SANs SSL with godaddy, so is set for the https://
when I type in the browser it goes to
and then i get the error about invalid certificate.

I need it to redirect automatically to

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


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?

Re: How to redirect the non-www address to the www

Posted: Wed Jun 07, 2017 5:24 pm
by dannykid91
dhuelsmann wrote:Try this code in your .htaccess changing it to fit your situation

Code: Select all

########## Begin - Redirecting non-www request to www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule (.*)$1 [L,R=301]
########## End - Redirecting non-www request to www
Thanks dhuelsmann. This is exactly what I need. Thanks so much ;) ;)

Re: How to redirect the non-www address to the www

Posted: Sat Nov 04, 2017 5:10 pm
by leo78
but it is better this way:

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