I want to 301 redirect the "home" link

Discussion regarding Joomla! Performance issues.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Security and Performance FAQs
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
sfraise
Joomla! Intern
Joomla! Intern
Posts: 59
Joined: Thu Sep 13, 2007 3:20 pm

I want to 301 redirect the "home" link

Post by sfraise » Tue Sep 23, 2008 9:10 am

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?

User avatar
davetanguay
Joomla! Hero
Joomla! Hero
Posts: 2511
Joined: Fri Sep 22, 2006 6:21 pm
Location: Orlando, FL
Contact:

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

Post by davetanguay » Tue Sep 23, 2008 7:09 pm

Have you tried using Artio JoomSEF as your SEF solution? It has an area which you can use to specify your 301 URLs.
CPanel Web Hosting Services http://interactiveonline.com/shared-web-hosting
Follow us on Twitter @interactiveo

sfraise
Joomla! Intern
Joomla! Intern
Posts: 59
Joined: Thu Sep 13, 2007 3:20 pm

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

Post by sfraise » Wed Sep 24, 2008 5:59 am

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

User avatar
davetanguay
Joomla! Hero
Joomla! Hero
Posts: 2511
Joined: Fri Sep 22, 2006 6:21 pm
Location: Orlando, FL
Contact:

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

Post by davetanguay » Wed Sep 24, 2008 7:49 am

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.
You do not have the required permissions to view the files attached to this post.
CPanel Web Hosting Services http://interactiveonline.com/shared-web-hosting
Follow us on Twitter @interactiveo

kremo5le
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 122
Joined: Thu Jul 31, 2008 9:23 pm
Location: United States

kRemtronicz 301 Redirect Not Working With sh404SF

Post by kremo5le » Thu Dec 04, 2008 7:28 pm

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

User avatar
davetanguay
Joomla! Hero
Joomla! Hero
Posts: 2511
Joined: Fri Sep 22, 2006 6:21 pm
Location: Orlando, FL
Contact:

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

Post by davetanguay » Thu Dec 04, 2008 11:40 pm

check your joomla config file and make sure the live site is set to http://mysite.com instead of http://www.mysite.com
CPanel Web Hosting Services http://interactiveonline.com/shared-web-hosting
Follow us on Twitter @interactiveo

kremo5le
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 122
Joined: Thu Jul 31, 2008 9:23 pm
Location: United States

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

Post by kremo5le » Fri Dec 05, 2008 12:09 am

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

User avatar
davetanguay
Joomla! Hero
Joomla! Hero
Posts: 2511
Joined: Fri Sep 22, 2006 6:21 pm
Location: Orlando, FL
Contact:

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

Post by davetanguay » Fri Dec 05, 2008 12:34 am

Within the configuration.php check the following line of code:

$mosConfig_live_site = 'http://mysite.com';
CPanel Web Hosting Services http://interactiveonline.com/shared-web-hosting
Follow us on Twitter @interactiveo

kremo5le
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 122
Joined: Thu Jul 31, 2008 9:23 pm
Location: United States

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

Post by kremo5le » Fri Dec 05, 2008 1:13 am

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)

undercash
Joomla! Intern
Joomla! Intern
Posts: 76
Joined: Fri Dec 12, 2008 12:24 am
Contact:

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

Post by undercash » Tue Dec 23, 2008 6:37 am

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

TheOmniAdam
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Dec 30, 2008 6:32 pm

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

Post by TheOmniAdam » Wed Jan 21, 2009 11:35 pm

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!

User avatar
davetanguay
Joomla! Hero
Joomla! Hero
Posts: 2511
Joined: Fri Sep 22, 2006 6:21 pm
Location: Orlando, FL
Contact:

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

Post by davetanguay » Wed Jan 21, 2009 11:45 pm

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.
CPanel Web Hosting Services http://interactiveonline.com/shared-web-hosting
Follow us on Twitter @interactiveo

TheOmniAdam
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Dec 30, 2008 6:32 pm

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

Post by TheOmniAdam » Thu Jan 22, 2009 1:03 am

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!

TheOmniAdam
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Dec 30, 2008 6:32 pm

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

Post by TheOmniAdam » Thu Jan 22, 2009 5:40 am

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?

egypty
Joomla! Apprentice
Joomla! Apprentice
Posts: 23
Joined: Mon Jun 09, 2008 11:02 am
Contact:

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

Post by egypty » Thu Jan 29, 2009 2:43 pm

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

User avatar
elixier
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Wed Sep 19, 2007 11:14 am
Contact:

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

Post by elixier » Wed May 27, 2009 5:47 pm

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.
Please read forum rules regarding signatures: http://forum.joomla.org/viewtopic.php?t=65

kremo5le
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 122
Joined: Thu Jul 31, 2008 9:23 pm
Location: United States

301 Redirect + sh404SEF

Post by kremo5le » Tue Jun 09, 2009 4:00 pm

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

User avatar
Ghonjez
Joomla! Exemplar
Joomla! Exemplar
Posts: 8770
Joined: Sat Oct 18, 2008 3:02 am
Location: Mars
Contact:

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

Post by Ghonjez » Sun Jun 21, 2009 12:53 am

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

User avatar
joomfriend
Joomla! Explorer
Joomla! Explorer
Posts: 284
Joined: Sun Feb 08, 2009 5:10 pm
Contact:

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

Post by joomfriend » Mon Jun 29, 2009 1:16 am

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.
- https://www.adelnipet.com: Adelni Pet - Your Social Pet Network
- https://www.egliseprimitive.org: Christian Website

orthodoxkohen
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Sun May 24, 2009 4:42 pm

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

Post by orthodoxkohen » Fri Aug 14, 2009 5:47 am

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?

kayser916
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Wed Jun 09, 2010 5:13 am

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

Post by kayser916 » Thu Jul 15, 2010 1:52 am

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.

g1smd
Joomla! Guru
Joomla! Guru
Posts: 951
Joined: Mon Feb 21, 2011 4:02 pm
Location: UK

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

Post by g1smd » Mon May 02, 2011 4:52 pm

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
Online since 1995.

i_prosperous
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Thu Nov 10, 2011 2:36 pm

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

Post by i_prosperous » Thu Nov 10, 2011 2:50 pm

Thanks g1smd

Very useful instruction.

doverrdov
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Sat Jan 28, 2012 10:19 am
Location: San Antonio
Contact:

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

Post by doverrdov » Sat Jan 28, 2012 10:30 am

hai

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

luis23045
Joomla! Explorer
Joomla! Explorer
Posts: 459
Joined: Mon Mar 09, 2009 9:54 am
Location: Dallas, TX
Contact:

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

Post by luis23045 » Wed Mar 07, 2012 4:43 am

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
http://cmsteachings.com - Joomla Tips & Tutorials
http://ubrainmedia.com - My Joomla Company
My Joomla Advice is my personal experience. It does not means I am right or wrong. It just means that I work with Joomla in my own way and it works for me.

g1smd
Joomla! Guru
Joomla! Guru
Posts: 951
Joined: Mon Feb 21, 2011 4:02 pm
Location: UK

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

Post by g1smd » Wed Mar 07, 2012 7:38 am

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]
Online since 1995.

luis23045
Joomla! Explorer
Joomla! Explorer
Posts: 459
Joined: Mon Mar 09, 2009 9:54 am
Location: Dallas, TX
Contact:

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

Post by luis23045 » Wed Mar 07, 2012 1:54 pm

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?
http://cmsteachings.com - Joomla Tips & Tutorials
http://ubrainmedia.com - My Joomla Company
My Joomla Advice is my personal experience. It does not means I am right or wrong. It just means that I work with Joomla in my own way and it works for me.

Donethat
Joomla! Explorer
Joomla! Explorer
Posts: 434
Joined: Fri May 30, 2008 12:36 pm
Location: Redhill
Contact:

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

Post by Donethat » Thu Mar 28, 2013 10:01 am

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?
Perfection is a state of mind, not reality
www.cavespider.co.uk

Donethat
Joomla! Explorer
Joomla! Explorer
Posts: 434
Joined: Fri May 30, 2008 12:36 pm
Location: Redhill
Contact:

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

Post by Donethat » Thu Mar 28, 2013 10:07 am

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.
Perfection is a state of mind, not reality
www.cavespider.co.uk

dermi
Joomla! Intern
Joomla! Intern
Posts: 55
Joined: Sat Jul 06, 2013 6:25 am

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

Post by dermi » Thu Sep 26, 2013 12:14 pm

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
Joomla! is an award-winning open source CMS for building powerful websites.
http://www.ecctv.ir . http://cantral.ir/panasonic-phone


Locked

Return to “Performance - 1.0.x”