Page 1 of 2

How to redirect the non-www address to the www

Posted: Sat Jan 03, 2009 8:21 pm
by avi2l
Hi, I'm sure this has been discussed a million times here, but I've followed some suggestions on different threads and I believe due to the passage of time, there may be a better option now days. My question is, what's my best option to redirect the non-www pages to the www, I beleive this referred to as canonicalization. In joomla 1.0, I didn't have this issue, or maybe sh404sef took care of this, but I tried adding to the .htaccess file and its not working for me. Is there an easy fix, like a sef-url component or plugin, or can someone give me the proper .htaccess code.

thanks in advance

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

Posted: Sat Jan 03, 2009 8:43 pm
by dhuelsmann
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} ^mysite.com [NC]
RewriteRule (.*) http://www.mysite.com/$1 [L,R=301]
#
########## End - Redirecting non-www request to www

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

Posted: Sat Jan 03, 2009 8:52 pm
by avi2l
Thank you dhuelsmann, i tried adding that code, but didn't work. Does it need to be placed in a particluar area, or need to replace anything?

thanks

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

Posted: Sat Jan 03, 2009 9:27 pm
by aaron_nimocks
Not to insult you but that code looks like it should work. Did you change the mysite to your sites name in both spots?

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

Posted: Sat Jan 03, 2009 9:38 pm
by avi2l
yes, i added the sites name in both positions and paced the code after "end joomla core sef" section. Was wondering if it went somewhere in particular or in place of some particular code.

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

Posted: Sat Jan 03, 2009 11:52 pm
by dhuelsmann
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 http://www.google.com
Now point your browser to: http://www.yoursite.com/google.html
If it redirects you to Google - mod_rewrite is working.
If it gives you an error - mod_rewrite is not working.

Note: Replace "www.yoursite.com" with your actual web site domain.

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

Posted: Sun Jan 04, 2009 7:11 pm
by avi2l
Thank you, it finally worked. The problem must have been in the placement of the code. As I had it at the end of the htaccess.

Thank you again for your time and patience.

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

Posted: Tue Feb 10, 2009 3:01 am
by roma64
First of all, I was not sure whether to select 'Post a Reply' or 'New Post' button for this redirecting from non-www to http://www.domain topic and I sincerely do apologize if I messed up.

this problem has been bugging me for some times now and a resolution would really let me sleep (LOL). I have Joomla 1.5.9 and my Core Joomla SEO Settings are as follow:

Search Engine Friendly URLs= Yes
Use Apache mod_rewrite = Yes ( tested it with the Redirect /google.html http://www.google.com and it took me to google after typing my domain.com/google.html)

I am not using any other SEO except the core Joomla one.


I read most of the forum regarding the topic of redirecting from non-www to http://www.domain with various changes to the RewriteCond and RewriteRule but with no luck. I am having problem with Google Webmaster Tool where it reports that my site's sitemap has the following warning:

All the URLs in your Sitemap are marked as having dynamic content.
All the URLs in your Sitemap are marked as having dynamic content (the value of is "always"). Because dynamic content is difficult for search engines to crawl and index, this may impact your site's performance in search results. Check your Sitemap to make sure your site information is correct.

my htaccess is as follow (I removed the real domain for I am not sure whether I should included or not for security reasons - My site has been hacked once before and I am trying to avoid that from happening again):

==================Start of htaccess======================

##
# @version $Id: htaccess.txt 10492 2008-07-02 06:38:28Z ircmaxell $
# @package Joomla
# @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
# @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
# Joomla! is Free Software
##


#####################################################
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE
#
# 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.
#
#####################################################

# 1and1 hosting fix
# If you are intending to use php 5 by default (recommended) then add the line below
AddType x-mapp-php5 .php

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

#
# mod_rewrite in use

RewriteEngine On

########## 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 set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via 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} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#
########## End - Joomla! core SEF Section
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /errordocument.html
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]


=================End of htaccess

As you can see from the first 4 lines from where the #End - Joomla! core SEF Section# starts above, I am also trying to setup a custom 404 error page (that should take visitors to a custom 404 error page with navigational menu but it is not working. I can only ask for 1 resolution at a time (both would be better though...LOL). Again, I am battling a war with Google Webmaster Tool regarding the Sitemap warning and I hate having errors or warnings regarding my site, therefore, your assistance with the above "redirecting from non-www to http://www.domain" issue would be greatly appreciated. Thanks a million.

Sincerely yours!

Roma64 :'(

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

Posted: Tue Feb 10, 2009 1:07 pm
by dhuelsmann
Your www redirection will not work because you placed it at the end of all other rewrites. Place it immediately after

Code: Select all

RewriteEngine On

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

Posted: Wed Feb 11, 2009 2:42 pm
by roma64
dhuelsmann! Thank you for your assistance and quick response. I did make the changes and it worked but now, when I click on any menu, I get the following error:

Bad Request - Your browser sent a request that this server could not understand.

I have not made any changes to my menus and maybe once I do that, the above error might go away. Once again, dhuelsmann, thank you for your quick response and assistance.

Sincerely yours!

Roma :p

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

Posted: Fri Feb 20, 2009 11:31 pm
by bkmjet
Hi, I'm trying to do this on my site, but I can't figure out why it isn't working. I'm posting my htaccess file below. I've tried numerous variations of what you said to do, but it's still not working.

Code: Select all

##
# @version $Id: htaccess.txt 10492 2008-07-02 06:38:28Z ircmaxell $
# @package Joomla
# @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
# @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
# Joomla! is Free Software
##


#####################################################
#  READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE
#
# 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

########## Begin - Redirecting non-www request to www
#
RewriteEngine On
RewriteCond %{HTTP_HOST} ^airplaneconnection.com [NC]
RewriteRule (.*) http://www.airplaneconnection.com/$1 [L,R=301]
#
########## End - Redirecting non-www request to www

########## 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 set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via 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} (/|\.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 22, 2009 3:20 pm
by roma64
bkmjet!

Thanks to dhuelsmann, I have my redirection working perfectly. Try the following .htaccess code:


##
# @version $Id: htaccess.txt 10492 2008-07-02 06:38:28Z ircmaxell $
# @package Joomla
# @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
# @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
# Joomla! is Free Software
##


#####################################################
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE
#
# 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
RewriteCond %{HTTP_HOST} ^airplaneconnection.com [NC]
RewriteRule (.*) http://www.airplaneconnection.com/$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 set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via 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} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#
########## End - Joomla! core SEF Section

I know you used the ########## Begin - Redirecting non-www request to www and ########## End - Redirecting non-www request to www lines , therefore, you can use the following rewrite code (right after the #mod_rewrite in use line):

RewriteEngine On
########## Begin - Redirecting non-www request to www
RewriteCond %{HTTP_HOST} ^airplaneconnection.com [NC]
RewriteRule (.*) http://www.airplaneconnection.com/$1 [L,R=301]
########## End - Redirecting non-www request to www

I hope this helps!

With Regards!!!

Roma64 :)

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

Posted: Wed Apr 15, 2009 8:35 pm
by bkmjet
Alright, I now it's been a while, but that suggestion didn't work, so I'm still looking for an answer if anybody has one

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

Posted: Thu Apr 16, 2009 12:01 pm
by Japanac033
If a web site is accessible under both http://www.example.com and example.com domains, you should be a responsible webmaster and remove the ambiguity altogether, through the following rewrite rules:

Code: Select all

RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
That should solve the problem ;)

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

Posted: Thu Apr 16, 2009 12:57 pm
by bkmjet
thanks, it works now

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

Posted: Thu Apr 23, 2009 2:20 am
by owetr
sory for re post but as i use above tutor for 301

Code: Select all

I use Com SEF Servicemap and which generates a sitemap for the site. This produces an xml file for Google which I have submitted.
I have received warnings:
"URLs not followed
When we tested a sample of URLs from your Sitemap, we found that some URLs redirect to other locations. We recommend that your Sitemap contain URLs that point to the final destination (the redirect target) instead of redirecting to another URL"

Before submit sitemap to google I use some trick to add www. <--- in htaccess such as I read the trick in this forum. but the urls sitemap that issued by sef servicemap in my site all resulted by non www. but urls that given warning by google run correctly.

so any body can help me to solve this problem?
Thank in advance :D
above in the box is my problem as i am insert the htacces bellow:

RewriteEngine On
########## Begin - Redirecting non-www request to www
RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule (.*) http://www.mydomain.com/$1 [L,R=301]
########## End - Redirecting non-www request to www

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

Posted: Thu Apr 23, 2009 5:24 am
by pasey
I tried this too and it works ok for me, thanks for this :)

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

Posted: Fri Apr 24, 2009 5:01 am
by softbranch
dhuelsmann wrote:Your www redirection will not work because you placed it at the end of all other rewrites. Place it immediately after

Code: Select all

RewriteEngine On
Thanks, I was looking for that.

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

Posted: Sun May 10, 2009 3:51 pm
by softbranch
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} ^mysite.com [NC]
RewriteRule (.*) http://www.mysite.com/$1 [L,R=301]
#
########## End - Redirecting non-www request to www

Thanks a million

I still Have this issue ive tried everything

Posted: Wed Dec 09, 2009 11:27 am
by hannahm23
I Have read this complete thread but still when I go to http://phelans.co.uk it errors.

This is my .htaccess file:

Code: Select all

##
# @version $Id: htaccess.txt 10492 2008-07-02 06:38:28Z ircmaxell $
# @package Joomla
# @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
# @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
# Joomla! is Free Software
##


#####################################################
#  READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE
#
# 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

RewriteCond %{HTTP_HOST} ^phelans.co.uk [NC]
RewriteRule (.*) http://www.phelans.co.uk/$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 set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via 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} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#
########## End - Joomla! core SEF Section
Can anyone see any issues with the redirect code??
Thank you,

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

Posted: Mon Dec 21, 2009 11:05 pm
by czarredd
Don't mean to scratch up this old thread but my issue is that I want to redirect my www to the non-www version of the site. Here is my htaccess....what did I do wrong here? Thanks in advance.

##
# @version $Id: htaccess.txt 13415 2009-11-03 15:53:25Z ian $
# @package Joomla
# @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
# @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
# Joomla! is Free Software
##


#####################################################
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE
#
# 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
RewriteCond %{HTTP_HOST} ^indiaredd.com [NC]
RewriteRule (.*) http://indiaredd.com/$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!
#
## Deny access to extension xml files (uncomment out to activate)
#<Files ~ "\.xml$">
#Order allow,deny
#Deny from all
#Satisfy all
#</Files>
## End of deny access to extension xml files
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via 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} (/|\.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: Thu Feb 11, 2010 9:06 pm
by rajeshatbuzz
I used above given explanation but not make it work. Plz find my .htacces.

where i changed the domain name to my domain name...

Code: Select all

##
# @version $Id: htaccess.txt 9975 2008-01-30 17:02:11Z ircmaxell $
# @package Joomla
# @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
# @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
# Joomla! is Free Software
##


#####################################################
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE
#
# 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
RewriteCond %{HTTP_HOST} ^sakkathhot.com [NC]
RewriteRule (.*) http://www.sakkathhot.com/$1 [L,R=301]

# 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} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#
########## End - Joomla! core SEF Section


########## 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 set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via 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

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

Posted: Fri Feb 12, 2010 6:50 am
by rajeshatbuzz
Hi Tried following code as well but error is coming like Redirect Loop...

Code: Select all

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^sakkathhot.com [NC]
RewriteRule ^(.*)$ http://www.sakkathhot.com/$1 [L,R=301]
</IfModule>
Please help me out.

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

Posted: Fri Feb 12, 2010 6:57 am
by rajeshatbuzz
Hi, I have tried following workaround to check whether mod rewrite is working or not and found that its working.

Code: Select all

writeEngine On
Options +FollowSymLinks
Redirect /google.html http://www.google.com
One important thing which i want to mentioned here is, My site is set subdirectories instead of root.

please suggest as i m getting confused what to do :(

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

Posted: Fri Feb 12, 2010 7:47 am
by rajeshatbuzz
After having R & D long, i could find following inputs.

1 . After applying all above code in .htacces && sh404sef disable - its working

2. If sh404sef is enable && "301 redirect from JOOMLA SEF to sh404SEF" is set yes - its not working

3. if sh404sef is enable && "301 redirect from JOOMLA SEF to sh404SEF" is set No - site is coming up but its pages are having 404 isses and domain name is getting added in url.


Any idea if we apply above mentioned code in .htaccess, what is the best suitable setting for sh404sef? my site link is www.sakkathhot.com

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

Posted: Tue Jun 08, 2010 8:50 am
by Pylon
Although it's good to know what you can do with .htaccess and how to do it, you can address your www/non-www issues with this extension http://extensions.joomla.org/extensions ... adata/5355

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

Posted: Tue Jun 08, 2010 5:23 pm
by v2interactive
Pylon wrote:Although it's good to know what you can do with .htaccess and how to do it, you can address your www/non-www issues with this extension http://extensions.joomla.org/extensions ... adata/5355
Yeah, I agree with above. If you're getting a headache over it just throw in this plugin and you'll be fine.

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

Posted: Mon Aug 23, 2010 7:26 pm
by Zaxxen
Japanac033 wrote:If a web site is accessible under both http://www.example.com and example.com domains, you should be a responsible webmaster and remove the ambiguity altogether, through the following rewrite rules:

Code: Select all

RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
That should solve the problem ;)
THIS IS THE SOLUTION :)

Thanx! :)

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

Posted: Tue Aug 24, 2010 9:07 pm
by serrbiz
We, like others, reccommend a .htaccess command line.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.you\.com
RewriteRule (.*) http://www.you.com/$1

However, if that doesn't work, you should contact your host provider and see if they have a different command they use...

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

Posted: Thu Dec 30, 2010 6:37 pm
by pe7er
Some code that could be used without specifying your domain name:

Code: Select all

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