View Single Post
  #1  
Old 02-20-2014, 09:36 PM
 
elmirage001 elmirage001 is offline
 

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

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.12 | reBOOT (reDUX) Template v4.7.12.9 | Live
X-Cart GoldPlus v4.7.12 | reBOOT (reDUX) Template v4.7.12.9 | Dev
  • XCARTMODS.CO.UK | reBOOT (reDUX) |
  • Performive Hosting | Linux | PHP v7.4.15 | MySQL v5.7.39 |
Reply With Quote