www.website.com vs website.com issue

General questions relating to Joomla! 1.5 There are other boards for more specific help on Joomla! features and extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Locked
ssanchez
Joomla! Intern
Joomla! Intern
Posts: 53
Joined: Tue Oct 13, 2009 4:19 pm

www.website.com vs website.com issue

Post by ssanchez » Sat May 28, 2011 9:12 pm

Hey all Im having this issue where when I use www.mywebsite.com I cant use the shopping cart properly. I just cant click on add product. When I use just mywebsite.com (without www) everything works perfect... I know this is more for joomla not virtuemart but I think this is a joomla thing.. does this have something to do with my .htacess?
here is what i have in my .htacess (please note I have 1and1 hosting)



------------htacess-------------------------------
##
# @version $Id: htaccess.txt 9100 2007-10-01 22:29:10Z jinx $
# @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
##

# Force register_globals OFF
AddType x-mapp-php5 .php

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

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

#
# mod_rewrite in use

RewriteEngine On


# 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|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
#
########## 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

--------------------------htaccess--------------------------------



I do have on in global settings
Search Engine Friendly URLs
Use Apache mod_rewrite
Use Apache mod_rewrite

I also have in virturmart
Site URL as http://websitename.com


Please any one help!!?

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

Re: www.website.com vs website.com issue

Post by g1smd » Sat May 28, 2011 9:36 pm

Your .htaccess file is four years out of date.

Get a new copy from the 1.5.23 (or later) or 1.6.2 (or later) installation files.

Add this code to redirect from www to non-www URLs.

Code: Select all

########## Begin - 301 Redirect
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(index|home)\.html?\ HTTP/
RewriteRule ^(([^/]+/)*)(index|home)\.html?$ http://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://example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} !^(example\.com)?$
RewriteRule (.*) http://example.com/$1 [R=301,L]
#
########## End - 301 Redirect
OR add this code to redirect from non-www to www URLs.

Code: Select all

########## Begin - 301 Redirect
#
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
though your original question asked about redirecting to non-www.


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.

Don't forget to rename it to .htaccess and add your line of custom code near the beginning.

Code: Select all

AddType x-mapp-php5 .php
Last edited by g1smd on Sat May 28, 2011 10:31 pm, edited 1 time in total.
Online since 1995.

ssanchez
Joomla! Intern
Joomla! Intern
Posts: 53
Joined: Tue Oct 13, 2009 4:19 pm

Re: www.website.com vs website.com issue

Post by ssanchez » Sat May 28, 2011 10:04 pm

thanks bro.. What I actually did was just add

########## Begin - Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
## If the above throws an HTTP 500 error, swap [R=301,L] with [R,L]
########## End - Redirect non-www to www



TO THE END OF HTACESS AND IT WORKED!

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

Re: www.website.com vs website.com issue

Post by g1smd » Sat May 28, 2011 10:09 pm

If you continue to disregard the advice you were given, you will end up with:

- double redirects for some requested non-canonical URLs, and

- exposure of previously rewritten internal server filepaths back out on to the web as new URLs.

Either of those could invoke serious indexing and ranking problems for your site.

Your code also fails to redirect some non-canonical URL requests, such as those beginning http://www.example.com:80/ with an appended port number.

Rule order is critical especially when the file contains both external redirects and internal rewrites, as is the exact coding used to perform those tasks.
Online since 1995.

khank816
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Fri Oct 26, 2012 4:50 am

Re: www.website.com vs website.com issue

Post by khank816 » Wed Oct 31, 2012 2:20 am

I have change my websites url to seo friendly url and its in joomla. so i need to redirect the old url to the new one but i have a problem I dont know how and i found some samples not working when i tried it. the worst thing is that my page rank is now affected from 3 it is now NA and cant search my domain on google.

for example, I will redirect one of the inner pages of my website, will this be code be ok?

#
RewriteCond %{HTTP_HOST} !^(www.example.com/index.php?inner&pages=01)?$
RewriteRule (.*) http://www.example.com/inner-pages-treatments$1 [R=301,L]
#


I am not good in programming so I am now frustrated with this joomla. my page rank is gone to NA, before i have 3.

are the code above correct? pls i need your help

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

Re: www.website.com vs website.com issue

Post by g1smd » Wed Oct 31, 2012 1:11 pm

khank816 wrote:RewriteCond %{HTTP_HOST} !^(http://www.example.com/index.php?inner&pages=01)?$
RewriteRule (.*) http://www.example.com/inner-pages-treatments$1 [R=301,L]
A URL is made up of several parts: protocol, hostname, folder and filename, and parameters.

The (.*) part matches all requests. It should be replaced by only the literal path and filename part of the request that you want to match, but without the leading slash.
HTTP_HOST can match only the hostname part of the request. It cannot match protocol, path, filename, nor parameters.
If you want to examine requested parameters, then you need to look at QUERY_STRING with a separate RewriteCond.

$1 is the captured path part of the original request (in this case, containing "index.php"). Are you sure you really want to re-append that?

The ! is "not", so your code has the effect of redirecting all requests to the new URL, even requests for the new URL itself are redirected. This results in an infinite loop for all requests to your site so nothing can be accessed and nothing can be indexed.
Online since 1995.

khank816
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Fri Oct 26, 2012 4:50 am

Re: www.website.com vs website.com issue

Post by khank816 » Wed Oct 31, 2012 3:11 pm

thanks for your reply, I really really appreciate it.

this is my old url:
http://www.mywebsite/index.php?option= com_content&view=article&id=46&Itemid=62

and then I changed it to be seo friendly urls and it becomes like this:

http://www.mywebsite/about-us

yes, I want the "/index.php to be remove", will it be ok?

I have this one sample below before I am going to put it on the .htaccess

RewriteEngine on
RewriteCond %{QUERY_STRING} id=46
RewriteRule ^index\.php$ /about-us/? [L,R=301]

is this ok? or should i write the whole url?

I also notice that some old urls redirect to different page and not the page they should go.

thank you very much for your help, i appreciate it.

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

Re: www.website.com vs website.com issue

Post by g1smd » Thu Nov 01, 2012 9:49 am

Code: Select all

RewriteCond %{QUERY_STRING} id=46
will also redirect requests for id=460, id=461, id=4600 etc.
Use:

Code: Select all

RewriteCond %{QUERY_STRING} (^|&)id=46(&|$)
The rule target should also contain the protocol and hostname otherwise a request for
http://www.example.com/index.php ?option=com_content&view=article&id=46&Itemid=62
will redirect to
http://www.example.com/about-us

and a request for
http://example.com/index.php ?option=com_content&view=article&id=46&Itemid=62
will redirect to
http://example.com/about-us

If you don't have a separate non-www to www redirect in place, then you now have a duplicate content problem.

If you do have a separate non-www to www canonicalisation redirect, then a request for the old non-www URL will create an unwanted multiple step redirect chain because two different rules have to run in order to get from the old to the new URL. This is also very bad.

Every redirect should contain the canonical hostname in the rule target in order to avoid these problems.
Online since 1995.

khank816
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Fri Oct 26, 2012 4:50 am

Re: www.website.com vs website.com issue

Post by khank816 » Tue Nov 06, 2012 3:10 am

Hi, I followed your suggestion and it worked, from 73 duplicates shown on google webmaster tool, it is now down to 8.

I am confused on the one you said about below:
If you do have a separate non-www to www canonicalisation redirect, then a request for the old non-www URL will create an unwanted multiple step redirect chain because two different rules have to run in order to get from the old to the new URL. This is also very bad.

Every redirect should contain the canonical hostname in the rule target in order to avoid these problems.
These 3 urls redirect only to one page, the front page:

/index.php/component/content/
/index.php?option=com_content&
/component/content/frontpage

if I wrote the 301 redirect like this, will it worked?

RewriteCond %{QUERY_STRING} (^|&)/index.php/component/content/(&|$)
RewriteRule ^index\.php$ /component/content/frontpage? [L,R=301]

RewriteCond %{QUERY_STRING} (^|&)/index.php?option=com_content&(&|$)
RewriteRule ^index\.php$ /component/content/frontpage? [L,R=301]

another one is this, old urls but the same display but I change already to new urls, which have this urls, /inside-my-page/51-my-inner-pages/ :
/index.php?option=com_content&view=article&id=51&Itemid=54">hair
/index.php?option=com_content&view=article&id=51&Itemid=54/

is this correct?
RewriteCond %{QUERY_STRING} (^|&)=51&Itemid=54&(&|$)
RewriteRule ^index\.php$ /51-my-inner-pages/ [L,R=301]

RewriteCond %{QUERY_STRING} (^|&)=51&Itemid=54/(&|$)
RewriteRule ^index\.php$ /51-my-inner-pages/ [L,R=301]

thanks and hope this will be solve.

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

Re: www.website.com vs website.com issue

Post by g1smd » Tue Nov 06, 2012 8:41 am

Since your redirect code does not include the canonical hostname in the redirect target, a request for non-www old URL will redirect to non-www new URL and a request for www old URL will redirect to www new URL. This is another duplicate content problem.

You might have a separate general non-www to www canonicalisation redirect. This doesn't completely solve the problem because requests for non-www old URL will create a multiple step redirection chain. Depending on the rule order this will be:
non-www old URL -> www old URL -> www new URL
non-www old URL -> non-www new URL -> www new URL
Both are a disaster.

Every RewriteRule that is configured as a redirect (as opposed to a rewrite) MUST include the canonical protocol and hostname in the rule target and the canonical non-www to www redirect MUST be the last listed redirect.
Online since 1995.


Locked

Return to “General Questions/New to Joomla! 1.5”