Page 1 of 1

I want to 301 redirect the "home" link

Posted: Tue Sep 23, 2008 9:10 am
by sfraise
In order to cut down on duplicant content I've 301 redirected the non www version of the url as well as the /index.php version of the home page url.

Now I'm trying to do a 301 redirect of the index.php?option=com_frontpage&Itemid=1 version of the home page but can't seem to find out how to do it anywhere. So far everything I've tried has failed.

Anyone know how to do this?

Re: I want to 301 redirect the "home" link

Posted: Tue Sep 23, 2008 7:09 pm
by davetanguay
Have you tried using Artio JoomSEF as your SEF solution? It has an area which you can use to specify your 301 URLs.

Re: I want to 301 redirect the "home" link

Posted: Wed Sep 24, 2008 5:59 am
by sfraise
I figured it out, here's the 301 redirects to use for this:

########## Begin - 301 Redirect
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite\.com$ [NC]
RewriteRule .* http://www.yoursite.com/ [L,R=301]
#
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.yoursite\.com$
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule index\.php$ http://www.yoursite.com/%1 [R=301,L]
#
RewriteCond %{QUERY_STRING} ^option=com_frontpage&Itemid=1$
RewriteRule ^index\.php$ http://www.yoursite.com/? [R=301,L]
########## End - 301 Redirect

Re: I want to 301 redirect the "home" link

Posted: Wed Sep 24, 2008 7:49 am
by davetanguay
I'm glad you got it to work but if you want an easier way to create your 301's, Artio JoomSEF works very nice. Below is a screenshot of the 301 config screen which is accessible via the Joomla back-end.

kRemtronicz 301 Redirect Not Working With sh404SF

Posted: Thu Dec 04, 2008 7:28 pm
by kremo5le
Hello there,

The code placed here simply doesn't work 100% right on my site. I'd like to keep my site's address without the "www" at the beginning (http://mysite.com). However, after placing this code I only get the "www" version. What needs to be tweaked out in order for this to work?

Another issue is that I would like the front page link to be re-directed to the "http://mysite.com" as well. How do I do this? I tried using the code here, and my administrator site wasn't working anymore.

Thank you for your help!!

kRem :)

Re: I want to 301 redirect the "home" link

Posted: Thu Dec 04, 2008 11:40 pm
by davetanguay
check your joomla config file and make sure the live site is set to http://mysite.com instead of http://www.mysite.com

Re: I want to 301 redirect the "home" link

Posted: Fri Dec 05, 2008 12:09 am
by kremo5le
davetanguay wrote:check your joomla config file and make sure the live site is set to http://mysite.com instead of http://www.mysite.com
Will this be the configuration.php file? If so, I didn't see anything there. Could you be a bit more specific since I'm not a PHP coder?

Thank you!

kRem

Re: I want to 301 redirect the "home" link

Posted: Fri Dec 05, 2008 12:34 am
by davetanguay
Within the configuration.php check the following line of code:

$mosConfig_live_site = 'http://mysite.com';

Re: I want to 301 redirect the "home" link

Posted: Fri Dec 05, 2008 1:13 am
by kremo5le
davetanguay wrote:Within the configuration.php check the following line of code:

$mosConfig_live_site = 'http://mysite.com';
Hey David,

It did work but only to avoid /index.php, but not for www. at the beginning. It still doesn't re-direct it to the address without www.

What would be next? I use sh404SEF and there's a 301 option, but I don't want to touch anything before making sure.

THANK YOU for your support. This is one of the only times I've gotten something solved in this forum...

kRem 8)

Re: I want to 301 redirect the "home" link

Posted: Tue Dec 23, 2008 6:37 am
by undercash
sfraise wrote:I figured it out, here's the 301 redirects to use for this:

########## Begin - 301 Redirect
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite\.com$ [NC]
RewriteRule .* http://www.yoursite.com/ [L,R=301]
#
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.yoursite\.com$
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule index\.php$ http://www.yoursite.com/%1 [R=301,L]
#
RewriteCond %{QUERY_STRING} ^option=com_frontpage&Itemid=1$
RewriteRule ^index\.php$ http://www.yoursite.com/? [R=301,L]
########## End - 301 Redirect

thanks a lot!! it works!

I have been looking how to make a no www>www redirection for a long time now with htaccess and it never worked. always got a 500 error. Now this rules! :)

Re: I want to 301 redirect the "home" link

Posted: Wed Jan 21, 2009 11:35 pm
by TheOmniAdam
sfraise wrote:I figured it out, here's the 301 redirects to use for this:

########## Begin - 301 Redirect
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite\.com$ [NC]
RewriteRule .* http://www.yoursite.com/ [L,R=301]
#
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.yoursite\.com$
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule index\.php$ http://www.yoursite.com/%1 [R=301,L]
#
RewriteCond %{QUERY_STRING} ^option=com_frontpage&Itemid=1$
RewriteRule ^index\.php$ http://www.yoursite.com/? [R=301,L]
########## End - 301 Redirect
Where do you put this code in order for it to work? I've been dying to find a way to auto redirect the non www. version of my site and nothing seems to work.

Barring that, the thread was started saying you were already doing a redirect- how did you accomplish even that?

I would REALLY appreciate the help on either or both subjects!

Re: I want to 301 redirect the "home" link

Posted: Wed Jan 21, 2009 11:45 pm
by davetanguay
Where do you put this code in order for it to work?
it's code you would place in a .htaccess file within your joomla root folder.

Re: I want to 301 redirect the "home" link

Posted: Thu Jan 22, 2009 1:03 am
by TheOmniAdam
It just has to go in there? Doesn't have to go anywhere specific? Sweeet.

I'm going to test it tonight. Thank you so much for your help!

Re: I want to 301 redirect the "home" link

Posted: Thu Jan 22, 2009 5:40 am
by TheOmniAdam
Hey- It's not working. All I really care for it to do is redirect the without-the-www. version to the with-www. version, but it isn't doing that. I put it at the bottom of my .htaccess file replacing yoursite with the the domainname of my site- no avail. Any suggestions?

Re: I want to 301 redirect the "home" link

Posted: Thu Jan 29, 2009 2:43 pm
by egypty
not working for me, i replaced"yoursite" with my domain and i got nothing,i have the home page on www.mysite.com/home.html and i want to redirect it to www.mysite.com to avoid losing pr(google page rank) also i want to redirect from non www to www

help in this please

Re: I want to 301 redirect the "home" link

Posted: Wed May 27, 2009 5:47 pm
by elixier
I have used the following code to redirect http://yoursite.com to http://www.yoursite.com

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

Note: Just change "yoursite" in above code with your domain name and put this code after "#RewritetBase" and "JoomlaSEF" in your .htaccess file. Make sure that this works only for Apache server.

I have tried it and it worked for me. You need not have to use any extention for these 301 redirects mentioned above. Just use this simple configuration and its all done.

301 Redirect + sh404SEF

Posted: Tue Jun 09, 2009 4:00 pm
by kremo5le
I have been using sh404SEF and it works but not completely. I still type http://www.mysite.com and it does not redirect me to the http://mysite.com.

I wonder what I'm doing wrong...

Re: I want to 301 redirect the "home" link

Posted: Sun Jun 21, 2009 12:53 am
by Ghonjez
egypty wrote:also i want to redirect from non www to www
Hi...

Visit this thread : http://forum.joomla.org/viewtopic.php?f=428&t=407735

Hope this helps. :)

Re: I want to 301 redirect the "home" link

Posted: Mon Jun 29, 2009 1:16 am
by joomfriend
davetanguay wrote:Within the configuration.php check the following line of code:

$mosConfig_live_site = 'http://mysite.com';
Thanks to davetanguay!

I would just like to point out that those who are running J 1.5.0 and above, this line of code is not:

$mosConfig_live_site = 'http://mysite.com';

but

var $live_site = 'http://mysite.com';

or

var $live_site = 'http://www.mysite.com';

I couldn't find the $mosConfig_live_site in my config file.

Thanks.

Re: I want to 301 redirect the "home" link

Posted: Fri Aug 14, 2009 5:47 am
by orthodoxkohen
elixier wrote:I have used the following code to redirect http://yoursite.com to http://www.yoursite.com

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

Note: Just change "yoursite" in above code with your domain name and put this code after "#RewritetBase" and "JoomlaSEF" in your .htaccess file. Make sure that this works only for Apache server.

I have tried it and it worked for me. You need not have to use any extention for these 301 redirects mentioned above. Just use this simple configuration and its all done.

What would you do to force from https://yoursite.com to https://www.yoursite.com?

Re: I want to 301 redirect the "home" link

Posted: Thu Jul 15, 2010 1:52 am
by kayser916
Firstly open configuration.php in the root.
$mosConfig_live_site = 'http://softwareonlinereviews.com';------to----
$mosConfig_live_site = 'http://www.softwareonlinereviews.com';
Generally it is ok here.
While if it is not available you should add the code in the .htaccess file in the root.
########## Begin - 301 Redirect
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^softwareonlinereviews\.com$ [NC]
RewriteRule .* http://www.softwareonlinereviews.com/ [L,R=301]
#
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.softwareonlinereviews\.com$
RewriteRule ^(.*)$ http://www.softwareonlinereviews.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule index\.php$ http://www.softwareonlinereviews.com/%1 [R=301,L]
#
RewriteCond %{QUERY_STRING} ^option=com_frontpage&Itemid=1$
RewriteRule ^index\.php$ http://www.softwareonlinereviews.com/? [R=301,L]
########## End - 301 Redirect
and you should replace softwareonlinereviews to your own domain name.

Re: I want to 301 redirect the "home" link

Posted: Mon May 02, 2011 4:52 pm
by g1smd
There are numerous syntax errors in the code above.

Additionally, the rules are in completely the wrong order. Some non-canonical requests will trigger an unwanted two-step or three-step redirection chain.

The code below fixes the errors:

Code: Select all

########## Begin - 301 Redirect
#
Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{QUERY_STRING} ^option=com_frontpage&Itemid=1$
RewriteRule ^(index\.php)?$ http://www.example.com/? [R=301,L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(index|home)\.html?\ HTTP/
RewriteRule ^(([^/]+/)*)(index|home)\.html?$ http://www.example.com/$1 [R=301,L]
#
RewriteCond %{THE_REQUEST} !^POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteCond %{SERVER_PORT}>s ^(443>(s)|[0-9]+>s)$
RewriteRule ^(([^/]+/)*)index\.php$ http%2://www.example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
########## End - 301 Redirect
I urge you to use the new .htaccess file that comes with Joomla 1.5.23 onwards and Joomla 1.6.2 onwards. Look for the file called htaccess.txt in the installer package. It contains a note showing exactly where the redirects should go (in addition to a number of other changes). Add your new redirect code in the file at the point it says "redirects go here", or similar.

If you're using Joomla 1.0, the existing .htaccess file has a number of interesting problems. The file can be replaced with the code shown below, and the redirects shown above can be added in where it says "redirects go here":

Code: Select all

##
# @version $Id$
# @package Joomla
# @copyright Copyright (C) 2005 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 URLs.  If they work, it has been set by your server administrator and
# you do not need it set here.
#
# Only use one of the two SEF sections that follow.  Lines that can be uncommented
# (and thus used) have only one #.  Lines with two #'s should not be uncommented.
# In the section that you don't use, all lines should start with #
#
# For Standard SEF, use the standard SEF section.  You can comment out all of the
# RewriteCond lines and reduce your server's load if you don't have directories in
# your root named 'component' or 'content'.
#
# If you are using a 3rd Party SEF or the Core SEF solution uncomment all of the
# lines in the '3rd Party or Core SEF' section.
#
#####################################################


##### SOLVING PROBLEMS WITH COMPONENT URLs THAT DON'T WORK #####
# SPECIAL NOTE FOR SMF USERS WHEN SMF IS INTEGRATED AND BRIDGED
# OR ANY SITUATION WHERE A COMPONENT's URLs AREN'T WORKING.
#
# In both the 'Standard SEF', and '3rd Party or Core SEF' sections the line:
# RewriteCond %{REQUEST_URI} ^/component/option,com [NC,OR] 
# is optional - see notes - and may need to be uncommented.
#
# If you are running your Joomla!/Mambo from a subdirectory the name of the
# subdirectory will need to be inserted into this line.  For example, if your
# Joomla!/Mambo is in a subdirectory called '/test/', change this:
# RewriteCond %{REQUEST_URI} ^/component/option,com [NC,OR]
# to this:
# RewriteCond %{REQUEST_URI} ^/test/component/option,com [NC,OR]
#
#####################################################


DirectoryIndex index.php index.html


##  Can be commented out if it 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 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})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule . index.php [F]
#
########## End - Rewrite rules to block out some common exploits


## 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.
#
## End - Custom redirects


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

# RewriteBase /


########## Begin - Joomla! core SEF Section
## Use this section if using ONLY Joomla! core SEF.
## ALL (RewriteCond) lines in this section are only required if you actually
## have directories named 'content' or 'component' on your server.
## If you do not have directories with these names, comment them out.
#
# RewriteCond %{REQUEST_URI} ^/component/option,com [NC,OR]
RewriteCond %{REQUEST_URI} (/[^.]*|\.(php|html?))$ [NC]
RewriteCond %{REQUEST_URI} !^index\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^co(mpon|nt)ent/ index.php [L]
#
########## End - Joomla! core SEF Section


########## Begin - 3rd Party SEF Section
## Use this section if you are using a 3rd party (non-Joomla! core)
## SEF extension - e.g. OpenSEF, 404_SEF, 404SEFx, SEF Advance, etc.
#
# RewriteCond %{REQUEST_URI} ^/component/option,com [NC,OR]
# RewriteCond %{REQUEST_URI} (/[^.]*|\.(php|html?))$ [NC]
# RewriteCond %{REQUEST_URI} !^index\.php
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule .* index.php [L]
#
########## End - 3rd Party SEF Section

Re: I want to 301 redirect the "home" link

Posted: Thu Nov 10, 2011 2:50 pm
by i_prosperous
Thanks g1smd

Very useful instruction.

Re: I want to 301 redirect the "home" link

Posted: Sat Jan 28, 2012 10:30 am
by doverrdov
hai

i have a problem with website url www and non www how to do 301 redirect in joomla

Re: I want to 301 redirect the "home" link

Posted: Wed Mar 07, 2012 4:43 am
by luis23045
You can double check what others are using up there, but this is what I personally use inside my blog to to get redirected from the site with www to the site without the www

I just insert the code from below inside the .htaccess file just after RewriteEngine On

Code: Select all


RewriteCond %{HTTP_HOST} ^www.mywebsite.com
RewriteRule (.*) http://mywebsite.com/$1 [R=301,L]
If you don't see .htaccess inside your Joomla Root Files you may need to rename the htaccess.txt file to .htaccess

Re: I want to 301 redirect the "home" link

Posted: Wed Mar 07, 2012 7:38 am
by g1smd
Your www to non-www code contains several syntax errors (literal periods must be escaped) and will not redirect a non-canonical request such as for http://example.com:80/ and so on.


This code fixes both issues:

Code: Select all

RewriteCond %{HTTP_HOST} !^(example\.com)?$
RewriteRule (.*) http://example.com/$1 [R=301,L]
and for non-www to www, use:

Code: Select all

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

Re: I want to 301 redirect the "home" link

Posted: Wed Mar 07, 2012 1:54 pm
by luis23045
g1smd wrote:Your www to non-www code contains several syntax errors (literal periods must be escaped) and will not redirect a non-canonical request such as for http://example.com:80/ and so on.
Can you show me inside my own domain name that the redirect I am using is not working for non-canonical request such as for http://example.com:80/?

Or at least produce an example where the non redirection to my non www, is not working?

Re: I want to 301 redirect the "home" link

Posted: Thu Mar 28, 2013 10:01 am
by Donethat
I've applied this as is and it works a treat on initial testing
########## Begin - 301 Redirect
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite\.com$ [NC]
RewriteRule .* http://www.yoursite.com/ [L,R=301]
#
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.yoursite\.com$
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule index\.php$ http://www.yoursite.com/%1 [R=301,L]
#
RewriteCond %{QUERY_STRING} ^option=com_frontpage&Itemid=1$
RewriteRule ^index\.php$ http://www.yoursite.com/? [R=301,L]
########## End - 301 Redirect
I tried applying the syntax corrections suggested
This code fixes both issues:
Code:
RewriteCond %{HTTP_HOST} !^(example\.com)?$
RewriteRule (.*) http://example.com/$1 [R=301,L]


and for non-www to www, use:
Code:
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
It caused a '301 loop'. Took the correction out and back to working fine. So maybe I applied the correction incorrectly. But on the basis the original is working, does it need fixing?

Re: I want to 301 redirect the "home" link

Posted: Thu Mar 28, 2013 10:07 am
by Donethat
Sorry davetanguay but I'm no fan of Artio's Joomsef. In principle it's a good idea but there were so many compatibility issues with other extensions etc it proved not to be something we could leave to our clients to manage.

Re: I want to 301 redirect the "home" link

Posted: Thu Sep 26, 2013 12:14 pm
by dermi
luis23045 wrote:You can double check what others are using up there, but this is what I personally use inside my blog to to get redirected from the site with www to the site without the www

I just insert the code from below inside the .htaccess file just after RewriteEngine On

Code: Select all


RewriteCond %{HTTP_HOST} ^www.mywebsite.com
RewriteRule (.*) http://mywebsite.com/$1 [R=301,L]
If you don't see .htaccess inside your Joomla Root Files you may need to rename the htaccess.txt file to .htaccess
thanks for help me
http://docs.joomla.org/How_do_you_block ... taccess%3F