How to redirect the non-www address to the www

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

Moderator: General Support Moderators

avi2l
Joomla! Intern
Joomla! Intern
Posts: 63
Joined: Tue Jul 17, 2007 8:13 pm
Contact:

How to redirect the non-www address to the www

Postby avi2l » Sat Jan 03, 2009 8:21 pm

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

User avatar
dhuelsmann
Joomla! Master
Joomla! Master
Posts: 19623
Joined: Sun Oct 02, 2005 12:50 am
Location: Omaha, NE
Contact:

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

Postby dhuelsmann » Sat Jan 03, 2009 8:43 pm

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
Regards, Dave
Past Treasurer Open Source Matters, Inc.
Past Global Moderator
http://www.kiwaniswest.org

avi2l
Joomla! Intern
Joomla! Intern
Posts: 63
Joined: Tue Jul 17, 2007 8:13 pm
Contact:

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

Postby avi2l » Sat Jan 03, 2009 8:52 pm

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

User avatar
aaron_nimocks
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Sat Jan 03, 2009 9:17 pm

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

Postby aaron_nimocks » Sat Jan 03, 2009 9:27 pm

Not to insult you but that code looks like it should work. Did you change the mysite to your sites name in both spots?

avi2l
Joomla! Intern
Joomla! Intern
Posts: 63
Joined: Tue Jul 17, 2007 8:13 pm
Contact:

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

Postby avi2l » Sat Jan 03, 2009 9:38 pm

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.

User avatar
dhuelsmann
Joomla! Master
Joomla! Master
Posts: 19623
Joined: Sun Oct 02, 2005 12:50 am
Location: Omaha, NE
Contact:

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

Postby dhuelsmann » Sat Jan 03, 2009 11:52 pm

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.
Regards, Dave
Past Treasurer Open Source Matters, Inc.
Past Global Moderator
http://www.kiwaniswest.org

avi2l
Joomla! Intern
Joomla! Intern
Posts: 63
Joined: Tue Jul 17, 2007 8:13 pm
Contact:

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

Postby avi2l » Sun Jan 04, 2009 7:11 pm

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.

User avatar
roma64
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 110
Joined: Mon Feb 12, 2007 12:18 pm
Location: Reading, PA
Contact:

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

Postby roma64 » Tue Feb 10, 2009 3:01 am

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 :'(
SimplerWebs

User avatar
dhuelsmann
Joomla! Master
Joomla! Master
Posts: 19623
Joined: Sun Oct 02, 2005 12:50 am
Location: Omaha, NE
Contact:

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

Postby dhuelsmann » Tue Feb 10, 2009 1:07 pm

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
Regards, Dave
Past Treasurer Open Source Matters, Inc.
Past Global Moderator
http://www.kiwaniswest.org

User avatar
roma64
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 110
Joined: Mon Feb 12, 2007 12:18 pm
Location: Reading, PA
Contact:

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

Postby roma64 » Wed Feb 11, 2009 2:42 pm

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
SimplerWebs

bkmjet
Joomla! Apprentice
Joomla! Apprentice
Posts: 36
Joined: Thu Jan 10, 2008 9:25 pm
Contact:

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

Postby bkmjet » Fri Feb 20, 2009 11:31 pm

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


Skavyx Aviation - http://www.skavyx.com

Signature rules: Literal URLs only - viewtopic.php?f=8&t=65

User avatar
roma64
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 110
Joined: Mon Feb 12, 2007 12:18 pm
Location: Reading, PA
Contact:

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

Postby roma64 » Sun Feb 22, 2009 3:20 pm

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 :)
SimplerWebs

bkmjet
Joomla! Apprentice
Joomla! Apprentice
Posts: 36
Joined: Thu Jan 10, 2008 9:25 pm
Contact:

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

Postby bkmjet » Wed Apr 15, 2009 8:35 pm

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
Skavyx Aviation - http://www.skavyx.com

Signature rules: Literal URLs only - viewtopic.php?f=8&t=65

Japanac033
Joomla! Apprentice
Joomla! Apprentice
Posts: 33
Joined: Wed Apr 15, 2009 7:42 am
Contact:

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

Postby Japanac033 » Thu Apr 16, 2009 12:01 pm

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 ;)

bkmjet
Joomla! Apprentice
Joomla! Apprentice
Posts: 36
Joined: Thu Jan 10, 2008 9:25 pm
Contact:

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

Postby bkmjet » Thu Apr 16, 2009 12:57 pm

thanks, it works now
Skavyx Aviation - http://www.skavyx.com

Signature rules: Literal URLs only - viewtopic.php?f=8&t=65

owetr
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Sun Apr 12, 2009 8:32 pm

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

Postby owetr » Thu Apr 23, 2009 2:20 am

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

pasey
Joomla! Intern
Joomla! Intern
Posts: 72
Joined: Tue Apr 14, 2009 5:48 am

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

Postby pasey » Thu Apr 23, 2009 5:24 am

I tried this too and it works ok for me, thanks for this :)
Yahoo Web Hosting for Joomla http://thehostpimp.com/yahoo.htm

softbranch
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Fri Apr 24, 2009 4:36 am

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

Postby softbranch » Fri Apr 24, 2009 5:01 am

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.

softbranch
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Fri Apr 24, 2009 4:36 am

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

Postby softbranch » Sun May 10, 2009 3:51 pm

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

hannahm23
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Thu Jul 30, 2009 12:46 pm

I still Have this issue ive tried everything

Postby hannahm23 » Wed Dec 09, 2009 11:27 am

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,

czarredd
Joomla! Apprentice
Joomla! Apprentice
Posts: 25
Joined: Fri Jul 04, 2008 1:51 am

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

Postby czarredd » Mon Dec 21, 2009 11:05 pm

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

User avatar
rajeshatbuzz
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 198
Joined: Wed Sep 24, 2008 6:06 pm
Location: Bangalore
Contact:

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

Postby rajeshatbuzz » Thu Feb 11, 2010 9:06 pm

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
cmsGalaxy Team, Web Developer, Bangalore, India
Website Design - Development - SEO - Joomla
www.cmsGalaxy.com

User avatar
rajeshatbuzz
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 198
Joined: Wed Sep 24, 2008 6:06 pm
Location: Bangalore
Contact:

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

Postby rajeshatbuzz » Fri Feb 12, 2010 6:50 am

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.
cmsGalaxy Team, Web Developer, Bangalore, India
Website Design - Development - SEO - Joomla
www.cmsGalaxy.com

User avatar
rajeshatbuzz
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 198
Joined: Wed Sep 24, 2008 6:06 pm
Location: Bangalore
Contact:

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

Postby rajeshatbuzz » Fri Feb 12, 2010 6:57 am

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 :(
cmsGalaxy Team, Web Developer, Bangalore, India
Website Design - Development - SEO - Joomla
www.cmsGalaxy.com

User avatar
rajeshatbuzz
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 198
Joined: Wed Sep 24, 2008 6:06 pm
Location: Bangalore
Contact:

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

Postby rajeshatbuzz » Fri Feb 12, 2010 7:47 am

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
cmsGalaxy Team, Web Developer, Bangalore, India
Website Design - Development - SEO - Joomla
www.cmsGalaxy.com

User avatar
Pylon
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 150
Joined: Tue Aug 28, 2007 3:29 pm
Location: London, UK
Contact:

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

Postby Pylon » Tue Jun 08, 2010 8:50 am

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/site-management/seo-a-metadata/5355
http://www.pylondesign.co.uk We don't design Pylons...
http://www.villasanraffaello.com Big Villa for holiday rental in Le Marche, Italy

User avatar
v2interactive
Joomla! Guru
Joomla! Guru
Posts: 823
Joined: Thu May 28, 2009 12:32 am
Location: Atlanta, GA
Contact:

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

Postby v2interactive » Tue Jun 08, 2010 5:23 pm

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/site-management/seo-a-metadata/5355


Yeah, I agree with above. If you're getting a headache over it just throw in this plugin and you'll be fine.
Josh
http://www.v2interactive.net - Atlanta Based Joomla Development and SEO

Zaxxen
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Sun Nov 15, 2009 9:14 pm

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

Postby Zaxxen » Mon Aug 23, 2010 7:26 pm

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! :)

User avatar
serrbiz
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 231
Joined: Mon Sep 18, 2006 3:48 pm
Location: Annapolis, Maryland
Contact:

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

Postby serrbiz » Tue Aug 24, 2010 9:07 pm

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...

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 21845
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, The Netherlands
Contact:

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

Postby pe7er » Thu Dec 30, 2010 6:37 pm

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]
Kind Regards,
Peter Martin, Global Moderator
https://db8.nl - Joomla specialist, Nijmegen, Nederland
Developer of Options Manager Lite https://db8.eu/download/file/options-manager-lite


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

Who is online

Users browsing this forum: No registered users and 7 guests