Zen Cart Logo
Forums / General Questions / I've deleted products. How do I redirect customers to new ones? or to search instead?

I've deleted products. How do I redirect customers to new ones? or to search instead?

Views: 17,131

Results 21 to 38 of 38
2 Apr 2010, 6:04 PM
#21
g1smd avatar

g1smd

Zen Follower

Join Date:
Mar 2010
Location:
UK
Posts:
449
Plugin Contributions:
0

I've deleted products. How do I redirect customers to new ones? or to search instead?

RewriteRule cannot 'see' query string data. It only sees the 'path part' of a URL, following the initial slash, up until the question mark.

Use a preceding RewriteCond testing %{QUERY_STRING} to see the parameter data, in the same way others have looked at THE_REQUEST and HTTP_HOST and REQUEST_URI.

Clear those parameters with a trailing question mark on the end of the target URL to stop them being re-appended.

Make sure that the most 'specific' rule is listed FIRST, otherwise you risk creating an unwanted 'redirection chain' for non-www requests.

3 Apr 2010, 5:44 AM
#22
yenmax avatar

yenmax

New Zenner

Join Date:
Sep 2006
Posts:
89
Plugin Contributions:
0

Re: I've deleted products. How do I redirect customers to new ones? or to search instead?

Hi,
I have question about rewrite my home page from http://mysite.com to http://www.mysite.com. How to write a code for 301 redirect. Please help. :(

3 Apr 2010, 12:06 PM
#23
loosefast avatar

loosefast

Zen Follower

Join Date:
Jun 2005
Posts:
199
Plugin Contributions:
0

Re: I've deleted products. How do I redirect customers to new ones? or to search instead?

having trouble 'seeing' what you are saying here. how would this be written so that the redirect would work correctly?

#Redirects product page 187 to index
RewriteRule ^index.php?main_page=product_info&cPath=65&products_id=187 http://www.example.com/ [R=301,L]

g1smd:

RewriteRule cannot 'see' query string data. It only sees the 'path part' of a URL, following the initial slash, up until the question mark.

3 Apr 2010, 10:32 PM
#24
g1smd avatar

g1smd

Zen Follower

Join Date:
Mar 2010
Location:
UK
Posts:
449
Plugin Contributions:
0

Re: I've deleted products. How do I redirect customers to new ones? or to search instead?

Look at the code several posts back. It has very similar constructs to what you need to use here.

Use a RewriteCond before the RewriteRule, and check the value of QUERY_STRING using a suitable pattern.

The pattern matching in RewriteRule matches only the path part of a URL.

That is, the pattern in RewriteRule sees only the emboldened part of the request:

www.example.com/[b]some/path/to-a-file[/b]?parameter=value

The preceding part can be checked by looking at HTTP_HOST using a RewriteCond.

The following part can be checked by looking at QUERY_STRING using a RewriteCond.

10 Apr 2010, 12:40 PM
#26
doodlebuckets avatar

doodlebuckets

Totally Zenned

Join Date:
Jul 2005
Posts:
497
Plugin Contributions:
0

Re: I've deleted products. How do I redirect customers to new ones? or to search instead?

So would someone be willing to look at my site and tell me the exact code I need? This is all above my head and my SEO guy says this is a major problem for me that needs fixing and why my PR is totally gone. I get a 302 before the 404 on deleted items. I'm willing to hire for services. Please let me know :) Thanks! Amy

10 Apr 2010, 8:35 PM
#27
g1smd avatar

g1smd

Zen Follower

Join Date:
Mar 2010
Location:
UK
Posts:
449
Plugin Contributions:
0

Re: I've deleted products. How do I redirect customers to new ones? or to search instead?

I'll bet you're using:ErrorDocument 404 [b]http://www.example.com[/b]/index.php?main_page=page_not_foundThis MUST be changed to:```
ErrorDocument 404 [b]/[/b]index.php?main_page=page_not_found


The ErrorDocument directive must NOT contain a domain name.
4 Feb 2011, 11:57 AM
#28
bonnit avatar

bonnit

Zen Follower

Join Date:
Jun 2009
Location:
Kent, UK
Posts:
350
Plugin Contributions:
0

Re: I've deleted products. How do I redirect customers to new ones? or to search instead?

im so sorry but i have been studying this thread for some time now trying to redirect a dynamic page (/index.php?main_page=product_info&products_id=537) to my index page (well preferably to the replacement product if possible but index if this is too complicated) and i am very out of my depth

im not using any seo mods to change urls, the only things i am using are rewrites for non www to www and index to root, but i can't for the life of me get the 301 redirect to work and i am trying to follow what you are saying about rewrite instead of redirect but again im really struggling, i dont know much about htaccess at all and im desperately trying to learn. is there anyway you could give a working example of what you are speaking about above please? i only have about ten products to redirect but they have pretty good rankings so i would like to redirect some of that back inot my site if possible.

with regards to the non www to www code i have used, i struggled with getting it to work on my server and ended up having to contact them direct for the code as no others worked that i had come across so that is what im using, i dont know if this is the reason for the old product 301 to diff page isnt working?

my htaccess is below:

RewriteEngine On

#canonical redirect from non www to www
RewriteCond %{HTTP_HOST} !^(www\.livvylou\.co.uk)?$
RewriteCond %{REQUEST_URI} !^/admin [NC]
RewriteRule (.*) http://www.livvylou.co.uk/$1 [R=301,L]

# Index Redirect to root
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(html?|php)\ HTTP/
RewriteRule ^index\.(html?|php)$ http://www.livvylou.co.uk/? [R=301,L]

ErrorDocument 404 /index.php?main_page=page_not_found

#redirect rss page to actual feed
redirect 301 /rss.php http://www.livvylou.co.uk/feed/general/feed.xml

#Redirect old products to index
RewriteRule ^/index.php?main_page=product_info&products_id=537 http://www.livvylou.co.uk/ [R=301,L]

any help at all would be very much appreciated.

4 Feb 2011, 12:08 PM
#29
mprough avatar

mprough

Totally Zenned

Join Date:
Nov 2007
Location:
Woodbine, Georgia, United States
Posts:
4,279
Plugin Contributions:
37

Re: I've deleted products. How do I redirect customers to new ones? or to search instead?

bonnit:

im so sorry but i have been studying this thread for some time now trying to redirect a dynamic page (/index.php?main_page=product_info&products_id=537) to my index page (well preferably to the replacement product if possible but index if this is too complicated) and i am very out of my depth

im not using any seo mods to change urls, the only things i am using are rewrites for non www to www and index to root, but i can't for the life of me get the 301 redirect to work and i am trying to follow what you are saying about rewrite instead of redirect but again im really struggling, i dont know much about htaccess at all and im desperately trying to learn. is there anyway you could give a working example of what you are speaking about above please? i only have about ten products to redirect but they have pretty good rankings so i would like to redirect some of that back inot my site if possible.

with regards to the non www to www code i have used, i struggled with getting it to work on my server and ended up having to contact them direct for the code as no others worked that i had come across so that is what im using, i dont know if this is the reason for the old product 301 to diff page isnt working?

my htaccess is below:

RewriteEngine On

#canonical redirect from non www to www
RewriteCond %{HTTP_HOST} !^(www.livvylou.co.uk)?$
RewriteCond %{REQUEST_URI} !^/admin [NC]
RewriteRule (.*) http://www.livvylou.co.uk/$1 [R=301,L]

Index Redirect to root

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.(html?|php)\ HTTP/
RewriteRule ^index.(html?|php)$ http://www.livvylou.co.uk/? [R=301,L]

ErrorDocument 404 /index.php?main_page=page_not_found

#redirect rss page to actual feed
redirect 301 /rss.php http://www.livvylou.co.uk/feed/general/feed.xml

#Redirect old products to index
RewriteRule ^/index.php?main_page=product_info&products_id=537 http://www.livvylou.co.uk/ [R=301,L]

> 
> any help at all would be very much appreciated.
 Try something like this


> RewriteCond %{QUERY_STRING} products_id=537 
> RewriteRule (.*) http://www.livvylou.co.uk/$1? [R=301,L]

~Melanie
4 Feb 2011, 12:16 PM
#30
bonnit avatar

bonnit

Zen Follower

Join Date:
Jun 2009
Location:
Kent, UK
Posts:
350
Plugin Contributions:
0

Re: I've deleted products. How do I redirect customers to new ones? or to search instead?

AMAZING!!!!

it worked, thank you SO much!

4 Feb 2011, 12:27 PM
#31
mprough avatar

mprough

Totally Zenned

Join Date:
Nov 2007
Location:
Woodbine, Georgia, United States
Posts:
4,279
Plugin Contributions:
37

Re: I've deleted products. How do I redirect customers to new ones? or to search instead?

bonnit:

AMAZING!!!!

it worked, thank you SO much!

Very welcome

~Melanie

4 Feb 2011, 2:41 PM
#32
bonnit avatar

bonnit

Zen Follower

Join Date:
Jun 2009
Location:
Kent, UK
Posts:
350
Plugin Contributions:
0

Re: I've deleted products. How do I redirect customers to new ones? or to search instead?

one more very quick question (sorry!!)

i also need to do this for some image folders which i uploaded as "/images/medium/products/gift cards/" rather than "/images/medium/products/gift_cards/" (had a space instead of underscore

would this be the same method or different?

4 Feb 2011, 2:48 PM
#33
mprough avatar

mprough

Totally Zenned

Join Date:
Nov 2007
Location:
Woodbine, Georgia, United States
Posts:
4,279
Plugin Contributions:
37

Re: I've deleted products. How do I redirect customers to new ones? or to search instead?

That you must really fix... cannot redirect it

4 Feb 2011, 2:56 PM
#34
bonnit avatar

bonnit

Zen Follower

Join Date:
Jun 2009
Location:
Kent, UK
Posts:
350
Plugin Contributions:
0

Re: I've deleted products. How do I redirect customers to new ones? or to search instead?

yes sorry, i have fixed the folder name on my server and products etc but i am still getting requests for those images and a 404 response, i meant in terms of redirecting them to the correct place rather than them searching for a broken url

7 Oct 2011, 5:49 AM
#35
arora_girl avatar

arora_girl

New Zenner

Join Date:
Jul 2010
Posts:
19
Plugin Contributions:
0

Re: I've deleted products. How do I redirect customers to new ones? or to search instead?

Hi

Can someone please tell me how to put mulitple product ids in Rewrite condition.

RewriteCond %{QUERY_STRING} products_id=537
RewriteRule (.*) http://www.livvylou.co.uk/$1? [R=301,L]

I am able to get this working for a single product id but dont know how to put multiple product ids in condition.

please help me in getting out of this.
thanks.

7 Oct 2011, 6:12 AM
#36
mprough avatar

mprough

Totally Zenned

Join Date:
Nov 2007
Location:
Woodbine, Georgia, United States
Posts:
4,279
Plugin Contributions:
37

Re: I've deleted products. How do I redirect customers to new ones? or to search instead?

This part is the query string

products_id=537

So for example changing it to

products_id=

would redirect all product pages.

You must identify a common string that all of the pages you want to redirect share.

~Melanie

14 Oct 2011, 10:46 PM
#37
deziner76hd avatar

deziner76hd

New Zenner

Join Date:
Oct 2008
Location:
Lakewood Ny
Posts:
26
Plugin Contributions:
0

Re: I've deleted products. How do I redirect customers to new ones? or to search instead?

mprough:

7thVeil, I have edited your code and have some other relevant information and technique regarding this issue here http://pro-webs.net/blog/2010/03/21/deleted-out-of-stock-products/

I have always forced a permanent redirect by hand (ultimate control), but I certainly understand the need for a more large scale dynamic solution. So I edited your code to achieve this.

Cheers,

Melanie
Melanie
I know this is an old post but I am having a similar issue with Sorry, the product was not found. on pages products have been roved I am using:
Zen Cart 1.3.9h
Patch: 1::
Database Patch Level: 1.3.9h
and the solution you gave didn't work in this version. Do you have any suggestions on how to fix this is the version in have mentioned?
Any help would be greatly appreciated.

This is what I am referring to:

How about a more dynamic solution?

In the forum thread we noted earlier, Zenner 7thVeil suggested using a php redirect to move these pages to the category page for their original location. This is an excellent technique for a dynamic solution. The code change supplied by 7thVeil, was very smart, but incomplete as it was returning a 302 in the header. We definitely do not want to return a 302, as this is a temporary redirect, but a permanent headache for your SEO campaign.

So I tweaked his alteration for the following which will send disabled and deleted products to their category page with a permanent 301 redirect. If no category exists they are sent to the product not found page.

In /includes/modules/pages/product_info/main_template_vars.php around line 31 find:

if ( $res->fields['total'] < 1 ) {

Just below this you will see

$tpl_page_body = '/tpl_product_info_noproduct.php';

Replace this line with

$requeststring = (isset($_GET['cPath']))?'&cPath='. (int)$_GET['cPath']:'';
    header( "HTTP/1.1 301 Moved Permanently" );
    header('location:index.php?main_page=index'.$requeststring);

Remember this is really a very dynamic solution and you are giving up the ultimate control over where this product page url should be sent. There is also the possibility, if you are using a SEO rewrite module, that this tweak will result in a double redirect. This is not a good situation, so if you apply this and the header for the pages is sending a double redirect, or worse, a loop... then this solution is not for you.
Gary

20 Feb 2012, 8:23 AM
#38
wirefram avatar

wirefram

New Zenner

Join Date:
Apr 2011
Posts:
95
Plugin Contributions:
0

Re: I've deleted products. How do I redirect customers to new ones? or to search instead?

Hello

did you find the way to make it work with 1.3.9h?

I tried, it redirects ok but creates a PHP fatal error for the line 188:

$zco_notifier->notify('NOTIFY_MAIN_TEMPLATE_VARS_EXTRA_PRODUCT_INFO');

PHP Warning: require(/my/site/domain.com/includes/templates/custom/templates) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /my/site/domain.com/includes/modules/pages/product_info/main_template_vars.php on line 188
[19-Feb-2012 19:50:27] PHP Fatal error: require() [<a href='function.require'>function.require</a>]: Failed opening required 'includes/templates/custom/templates' (include_path='.:/usr/local/lib/php') in /my/site/domain.com/includes/modules/pages/product_info/main_template_vars.php on line 188

...