Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

301 Redirect deleted product to new page instead of 404
 
Reply
   X-Cart forums > X-Cart 4 > Changing and adding new features
 
Thread Tools Search this Thread
  #1  
Old 02-20-2014, 09:36 PM
 
elmirage001 elmirage001 is offline
 

X-Wizard
  
Join Date: Apr 2007
Posts: 1,518
 

Default 301 Redirect deleted product to new page instead of 404

A user asked this question in another thread and instead of hijacking it I'm starting this one. I'm posting the edit here in hopes that other will chime in and let us know if there is a better way.

I will be using a more involved version of this that will 301 for certain filtered URLs and 404 everything else. I'm not sure if this is the best way to accomplish this or not but using a server response checker everything is working okay.

I know that it's best to not delete product but we have a unique business that specializes in products that are "one of a kind" and when it's sold it can't be replaced so you have to upload a new product of the same group. The reality is that to keep your sanity you must delete sold items from time to time.

In include/func/func.core.php around line 3133

Change:
Code:
if ($HTTPS) $base_replacement = '<base href="https://' . $xcart_https_host . $xcart_web_dir . '/"'; else $base_replacement = '<base href="http://' . $xcart_http_host . $xcart_web_dir . '/"'; @header("HTTP/1.0 404 Not Found"); if ($is_found) { echo preg_replace('/<base\s+href=".*"/USs', $base_replacement , implode("", file($filename404))); } exit; }
To:
Code:
if ($HTTPS) $base_replacement = '<base href="https://' . $xcart_https_host . $xcart_web_dir . '/"'; else $base_replacement = '<base href="http://' . $xcart_http_host . $xcart_web_dir . '/"'; //@header("HTTP/1.0 404 Not Found"); //if ($is_found) { // echo preg_replace('/<base\s+href=".*"/USs', $base_replacement , implode("", file($filename404))); //} @header("HTTP/1.1 301 Moved Permanently"); @header("Location: http://www.your_url.com/"); exit; }
Thank you, Paul
__________________
X-Cart GoldPlus v4.7.11 | PHP 7.2
  • XCARTMODS.CO.UK | reBOOT Template |
  • Smack Digital | CDSEO Pro 2.0 + Custom Replacements | Category SEO Map |
  • Total Server Solutions Hosting | Linux | PHP v7.2 | MySQL v5.6.40 |
Reply With Quote
  #2  
Old 02-20-2014, 10:00 PM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 13,413
 

Default Re: 301 Redirect deleted product to new page instead of 404

If this is for products only probably better to do it here

func.product.php around line 2430 if product is not found or disabled

PHP Code:
func_403(33);
            } else {
                
func_page_not_found();
            }
        } else {
            return 
false;
        } 

replace the one you need with

func_header_location($location, true, 301, true, false);

Replace $location with where you want it to go like 'home.php', or 'home.php?cat=XX', or static page...

This func_select_product is called by product.php. Keep in mind though that same function is probably called on other occasions to list products so probably best to replace the func_403 or func_page_not_found with the new code and leave the "return false" as is
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote

The following user thanks cflsystems for this useful post:
elmirage001 (02-20-2014)
  #3  
Old 02-20-2014, 10:06 PM
 
elmirage001 elmirage001 is offline
 

X-Wizard
  
Join Date: Apr 2007
Posts: 1,518
 

Default Re: 301 Redirect deleted product to new page instead of 404

Hi Steve,

That's excellent! I was hoping you'd show me a better way.
As always I'm very appreciative of your help! Paul
__________________
X-Cart GoldPlus v4.7.11 | PHP 7.2
  • XCARTMODS.CO.UK | reBOOT Template |
  • Smack Digital | CDSEO Pro 2.0 + Custom Replacements | Category SEO Map |
  • Total Server Solutions Hosting | Linux | PHP v7.2 | MySQL v5.6.40 |
Reply With Quote
  #4  
Old 02-20-2014, 10:35 PM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 13,413
 

Default Re: 301 Redirect deleted product to new page instead of 404

No problem
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Changing and adding new features


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 12:58 PM.

   

 
X-Cart forums © 2001-2018