cutecat Posted June 9, 2013 Share Posted June 9, 2013 Hi guys, Currently I have viewed some of my visitors track, and they have entered a few 404 pages, is it possible to redirect them to my homepage instead of letting them see 404 page? Link to comment Share on other sites More sharing options...
Dh42 Posted June 9, 2013 Share Posted June 9, 2013 It is in your htaccess file on your server. Link to comment Share on other sites More sharing options...
cutecat Posted June 9, 2013 Author Share Posted June 9, 2013 this is in the htaccess default is this #If rewrite mod isn't enabled ErrorDocument 404 /index.php?controller=404 i changed to this ErrorDocument 404 /index.php and it still shows 404 page. there is also a 404.php in my root too. but I am not sure how to edit. Pls advise Link to comment Share on other sites More sharing options...
El Patron Posted June 9, 2013 Share Posted June 9, 2013 try this post: http://www.prestashop.com/forums/index.php?/topic/56695-404-redirect-page-to-homepage/page__view__findpost__p__356306 Link to comment Share on other sites More sharing options...
dorje Posted June 9, 2013 Share Posted June 9, 2013 the ErrorDocument 404 /prestashop/404.php in .htacess should handle your 404 properly but if you want to redirect your all 404 pages then you should use this code in htacess instead of the above one ErrorDocument 404 / But i personally dont recommend it because it will redirect all 404 pages to your homepage and it will not help you to track the site original 404 issues. Link to comment Share on other sites More sharing options...
cutecat Posted June 9, 2013 Author Share Posted June 9, 2013 the ErrorDocument 404 /prestashop/404.php in .htacess should handle your 404 properly but if you want to redirect your all 404 pages then you should use this code in htacess instead of the above one ErrorDocument 404 / But i personally dont recommend it because it will redirect all 404 pages to your homepage and it will not help you to track the site original 404 issues. i had some of my customers who are acting smarting smart by removing the product name to do to the category. which gave them an error page also I have placed ErrorDocument 404 /index.php and it does not work either Link to comment Share on other sites More sharing options...
Frenkie Posted June 12, 2013 Share Posted June 12, 2013 (edited) I have the same problem ... want to redirect all 404 errors to Homepage ... solution ErrorDocument 404 / dosent work. Possible solution: set friendlly url for 404 and then redirect this url to homepage you have to put this code in htaccess: # Redirect Redirect 301 /page-not-found http://www.homepage.com In my case friendly url is working for all pages except 404 error pages, so i can not do that. Edited June 12, 2013 by Frenkie (see edit history) Link to comment Share on other sites More sharing options...
dorje Posted June 13, 2013 Share Posted June 13, 2013 Best way to solve the 404 issue is to track the 404 errors in Google webmaster and Google analytic and redirect them manually by htacess. Link to comment Share on other sites More sharing options...
Frenkie Posted June 14, 2013 Share Posted June 14, 2013 No Dorje that is not the Idea. I want that everyone, even those who type wrong address, come on page with marketing content not on ugly 404 error. This is also double work. Why not just redirect all 404 errors to the homepage? Link to comment Share on other sites More sharing options...
siblibusro Posted June 14, 2013 Share Posted June 14, 2013 is anyone success fix this trouble ? baju murah Link to comment Share on other sites More sharing options...
siblibusro Posted June 26, 2013 Share Posted June 26, 2013 if you want redirect error 404 you should edit in controller folder 1 Link to comment Share on other sites More sharing options...
cutecat Posted July 16, 2013 Author Share Posted July 16, 2013 if you want redirect error 404 you should edit in controller folderHow did you do that?It looks great!Can shine some lights for us? Link to comment Share on other sites More sharing options...
scorpionsworld Posted July 16, 2013 Share Posted July 16, 2013 (edited) Why not edit the 404 template file in the theme to do a javascript redirect? That way you will still be able to track 404 errors and at the same time serve your visitors the homepage or any marketing page you want. Just add: <script type="text/javascript"> <!-- window.location.replace("yoururl"); //--> </script> Edited July 16, 2013 by scorpionsworld (see edit history) 2 Link to comment Share on other sites More sharing options...
cutecat Posted July 17, 2013 Author Share Posted July 17, 2013 Why not edit the 404 template file in the theme to do a javascript redirect? That way you will still be able to track 404 errors and at the same time serve your visitors the homepage or any marketing page you want. Just add: <script type="text/javascript"> <!-- window.location.replace("yoururl"); //--> </script> this is what i had done. but it still does not show my homepage <?php /* * 2007-2013 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2013 PrestaShop SA * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ require_once(dirname(__FILE__).'/config/config.inc.php'); Tools::displayFileAsDeprecated(); /* Controller::getController('PageNotFoundController')->run(); */ <script type="text/javascript"> <!-- window.location.replace("http://123.com/"); //--> </script> Link to comment Share on other sites More sharing options...
scorpionsworld Posted July 17, 2013 Share Posted July 17, 2013 (edited) this is what i had done. but it still does not show my homepage <?php /* * 2007-2013 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2013 PrestaShop SA * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ require_once(dirname(__FILE__).'/config/config.inc.php'); Tools::displayFileAsDeprecated(); /* Controller::getController('PageNotFoundController')->run(); */ <script type="text/javascript"> <!-- window.location.replace("http://123.com/"); //--> </script> That's because you placed the javascript in the wrong file. PHP is not able to execute Javascript, only parse PHP code before sending it to the browser, who in turn does know how to execute Javascript.And don't comment out the getController function, it will kill the 404 error tracking and parsing the template. Why not edit the 404 template file in the theme to do a javascript redirect? Edited July 17, 2013 by scorpionsworld (see edit history) 1 Link to comment Share on other sites More sharing options...
siblibusro Posted July 17, 2013 Share Posted July 17, 2013 (edited) you should edit the pagenotfoundcontroller.php in controller folder open your controller folder and edit pagenotfoundcontroller.php just copy and paste into pagenotfoundcontroller.php and change the http://tegalgubug.net to your homepage <?php /* * 2007-2013 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.or...ses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2013 PrestaShop SA * @license http://opensource.or...ses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class PageNotFoundControllerCore extends FrontController { /*ini sudah diganti */ public $php_self = '404'; public $page_name = 'pagenotfound'; /** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { /*here you should change your homepage */ header("Location: http://tegalgubug.net/"); if (in_array(Tools::strtolower(substr($_SERVER['REQUEST_URI'], -3)), array('png', 'jpg', 'gif'))) { header('Content-Type: image/gif'); readfile(_PS_IMG_DIR_.'404.gif'); exit; } elseif (in_array(Tools::strtolower(substr($_SERVER['REQUEST_URI'], -3)), array('.js', 'css'))) exit; parent::initContent(); $this->setTemplate(_PS_THEME_DIR_.'404.tpl'); } public function canonicalRedirection($canonical_url = '') { // 404 - no need to redirect to the canonical url } } ----- toko obat herbal |obat alami------ Edited July 17, 2013 by siblibusro (see edit history) 6 Link to comment Share on other sites More sharing options...
siblibusro Posted July 17, 2013 Share Posted July 17, 2013 (edited) if you edit pagenotfoundcontroller.phpyou can still be able track 404 error page in back office Edited September 22, 2013 by vekia (see edit history) 3 Link to comment Share on other sites More sharing options...
cutecat Posted July 17, 2013 Author Share Posted July 17, 2013 thanks mate. got it working! Link to comment Share on other sites More sharing options...
kokoliko Posted August 1, 2013 Share Posted August 1, 2013 siblibusro you are a hero Thank you for sharing this . Link to comment Share on other sites More sharing options...
syntaxed Posted August 13, 2013 Share Posted August 13, 2013 I have new visitors from 404 pages. Instead of just redirecting them, I offer a special voucher at that 404 page to attract them searching my store, instead of 'forcing' them to view things they are not originally looking for. do you all think it is a good thing to do? Link to comment Share on other sites More sharing options...
dorje Posted August 14, 2013 Share Posted August 14, 2013 (edited) But the redirect is 302 instead of 301 in your shop and how to get the 301 redirect. Also its not working for the .1.4.7.3 version.. Edited August 14, 2013 by dorje (see edit history) Link to comment Share on other sites More sharing options...
kir Posted September 22, 2013 Share Posted September 22, 2013 you should edit the pagenotfoundcontroller.php in controller folder open your controller folder and edit pagenotfoundcontroller.php just copy and paste into pagenotfoundcontroller.php and change the http://tegalgubug.net to your homepage <?php /* * 2007-2013 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.or...ses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2013 PrestaShop SA * @license http://opensource.or...ses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class PageNotFoundControllerCore extends FrontController { /*ini sudah diganti */ public $php_self = '404'; public $page_name = 'pagenotfound'; /** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { /*here you should change your homepage */ header("Location: http://tegalgubug.net/"); if (in_array(Tools::strtolower(substr($_SERVER['REQUEST_URI'], -3)), array('png', 'jpg', 'gif'))) { header('Content-Type: image/gif'); readfile(_PS_IMG_DIR_.'404.gif'); exit; } elseif (in_array(Tools::strtolower(substr($_SERVER['REQUEST_URI'], -3)), array('.js', 'css'))) exit; parent::initContent(); $this->setTemplate(_PS_THEME_DIR_.'404.tpl'); } public function canonicalRedirection($canonical_url = '') { // 404 - no need to redirect to the canonical url } } ----- toko obat herbal |obat alami------ God bless you my friend!!!!Thank you so much for this solution.I was looking for this last days.Work like a charm .thank you Link to comment Share on other sites More sharing options...
Pippo3000 Posted October 16, 2013 Share Posted October 16, 2013 That's because you placed the javascript in the wrong file. PHP is not able to execute Javascript, only parse PHP code before sending it to the browser, who in turn does know how to execute Javascript. And don't comment out the getController function, it will kill the 404 error tracking and parsing the template. worked for me, thanks for the tip! Link to comment Share on other sites More sharing options...
White Lion Posted October 18, 2013 Share Posted October 18, 2013 Dear friends. This website has a great way. Its 404 page automatically redirect to home page in 30 seconds. Try this link http://www.naaptol.com/thisiswronglink I think that is most suitable way. How we create our Prestashop 404 page with that method. If anyone find a way, Please update this topic. It will help to everyone. Link to comment Share on other sites More sharing options...
scorpionsworld Posted October 18, 2013 Share Posted October 18, 2013 Dear friends. This website has a great way. Its 404 page automatically redirect to home page in 30 seconds. Try this link http://www.naaptol.com/thisiswronglink I think that is most suitable way. How we create our Prestashop 404 page with that method. If anyone find a way, Please update this topic. It will help to everyone. Just check the source of this 404 page. The redirect is not in 30 seconds, but 5 seconds. <META HTTP-EQUIV="refresh" content="5; url=/"> Not suitable for Prestashop implementation. Besides, wether you think this way is most suitable is irrelevant. It's up to every shop owner to decide what best suites his shop or purpose of the 404 landing page. Link to comment Share on other sites More sharing options...
Dh42 Posted October 18, 2013 Share Posted October 18, 2013 Just do like I did with this site, show products http://zpalette.com/page-not-found?category_name=dogs Link to comment Share on other sites More sharing options...
White Lion Posted October 19, 2013 Share Posted October 19, 2013 Hello Dh42 Yes. That is good idea. scorpionsworld is correct. We need most suitable way to our needs. Link to comment Share on other sites More sharing options...
terungwa Posted December 7, 2013 Share Posted December 7, 2013 You can use Location Header function to redirect a page. This script works when we have not send any php or html command to out put any thing in the browser. Care is to be taken not to send any other thing to the browser after the header redirection using location command. Here is the code. <?phpheader("HTTP/1.1 301 Moved Permanently");header ("Location: your homepage here");exit;?> Simply drop the code above at the top of the controllers/front/PageNotFoundController.php file Link to comment Share on other sites More sharing options...
thewidezone Posted October 12, 2014 Share Posted October 12, 2014 Thanks Siblibusro your solution worked fine Link to comment Share on other sites More sharing options...
sapcha Posted November 10, 2014 Share Posted November 10, 2014 Hi, You can use this module : http://sapcha.com/boutique/8-module-de-redirection-301-302.html Thank's Adam 1 Link to comment Share on other sites More sharing options...
cille5 Posted January 29, 2015 Share Posted January 29, 2015 What I should edit on this "pagenotfoundcpntroller.php" file to redirect 404 error to fronpage? Website: seksituotteet.fi Prestashop 1.6.0.9 <?php /* * 2007-2014 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2014 PrestaShop SA * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class PageNotFoundControllerCore extends FrontController { public $php_self = '404'; public $page_name = 'pagenotfound'; public $ssl = true; /** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); if (preg_match('/\.(gif|jpe?g|png|ico)$/i', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) { $this->context->cookie->disallowWriting(); if (!isset($_SERVER['REDIRECT_URL'])) { $_SERVER['REDIRECT_URL'] = ''; if (preg_match('@^'.__PS_BASE_URI__.'([0-9]+)\-([_a-zA-Z0-9-]+)(/[_a-zA-Z0-9-]+)?\.jpg$@', $_SERVER['REQUEST_URI'], $matches)) $_SERVER['REDIRECT_URL'] = __PS_BASE_URI__.'p/'.Image::getImgFolderStatic($matches[0]).'/'.$matches[0].'-'.$matches[1].'.jpg'; } if (preg_match('#/p[0-9/]*/([0-9]+)\-([_a-zA-Z]*)\.(png|jpe?g|gif)$#', $_SERVER['REDIRECT_URL'], $matches)) { // Backward compatibility since we suffixed the template image with _default if (Tools::strtolower(substr($matches[2], -8)) != '_default') Link to comment Share on other sites More sharing options...
cille5 Posted January 29, 2015 Share Posted January 29, 2015 thx, but didn't work. I add this line to end of .htaccess file RewriteCond %{REQUEST_FILENAME} !-f # and the requested path and file doesn't directly match a physical folder RewriteCond %{REQUEST_FILENAME} !-d # internally rewrite the request to the index.php script RewriteRule .* index.php [L] Link to comment Share on other sites More sharing options...
cille5 Posted January 29, 2015 Share Posted January 29, 2015 page-not-found Link to comment Share on other sites More sharing options...
cille5 Posted January 30, 2015 Share Posted January 30, 2015 (edited) I edit the code in PAGENOTFOUNDCONTROLLER.PHP file like this. And now Redirect works. Orginal code was: header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); I replace it with this: Now page loading mark doesent stop at all. See image. Edited February 1, 2015 by cille5 (see edit history) Link to comment Share on other sites More sharing options...
Elaine Leung Posted April 4, 2015 Share Posted April 4, 2015 May I ask you what did you replace with to get it work. Kind regards Elaine Link to comment Share on other sites More sharing options...
PrestaShark Posted July 19, 2016 Share Posted July 19, 2016 For 1.6.1.5 <?php /* * 2007-2016 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2016 PrestaShop SA * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class PageNotFoundControllerCore extends FrontController { public $php_self = 'pagenotfound'; public $page_name = 'pagenotfound'; public $ssl = true; /** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { // header('HTTP/1.1 404 Not Found'); // header('Status: 404 Not Found'); header("Location: http://prestashark.eu/"); if (preg_match('/\.(gif|jpe?g|png|ico)$/i', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) { $this->context->cookie->disallowWriting(); if (!isset($_SERVER['REDIRECT_URL'])) { $_SERVER['REDIRECT_URL'] = ''; if (preg_match('@^'.__PS_BASE_URI__.'([0-9]+)\-([_a-zA-Z0-9-]+)(/[_a-zA-Z0-9-]+)?\.jpg$@', $_SERVER['REQUEST_URI'], $matches)) { $_SERVER['REDIRECT_URL'] = __PS_BASE_URI__.'p/'.Image::getImgFolderStatic($matches[0]).'/'.$matches[0].'-'.$matches[1].'.jpg'; } } if (preg_match('#/p[0-9/]*/([0-9]+)\-([_a-zA-Z]*)\.(png|jpe?g|gif)$#', $_SERVER['REDIRECT_URL'], $matches)) { // Backward compatibility since we suffixed the template image with _default if (Tools::strtolower(substr($matches[2], -8)) != '_default') { header('Location: '.$this->context->link->getImageLink('', $matches[1], $matches[2]), true, 302); exit; } else { $image_type = ImageType::getByNameNType($matches[2], 'products'); if ($image_type && count($image_type)) { $root = _PS_PROD_IMG_DIR_; $folder = Image::getImgFolderStatic($matches[1]); $file = $matches[1]; $ext = '.'.$matches[3]; if (file_exists($root.$folder.$file.$ext)) { if (ImageManager::resize($root.$folder.$file.$ext, $root.$folder.$file.'-'.$matches[2].$ext, (int)$image_type['width'], (int)$image_type['height'])) { header('HTTP/1.1 200 Found'); header('Status: 200 Found'); header('Content-Type: image/jpg'); readfile($root.$folder.$file.'-'.$matches[2].$ext); exit; } } } } } elseif (preg_match('#/c/([0-9]+)\-([_a-zA-Z]*)\.(png|jpe?g|gif)$#', $_SERVER['REDIRECT_URL'], $matches)) { $image_type = ImageType::getByNameNType($matches[2], 'categories'); if ($image_type && count($image_type)) { $root = _PS_CAT_IMG_DIR_; $file = $matches[1]; $ext = '.'.$matches[3]; if (file_exists($root.$file.$ext)) { if (ImageManager::resize($root.$file.$ext, $root.$file.'-'.$matches[2].$ext, (int)$image_type['width'], (int)$image_type['height'])) { header('HTTP/1.1 200 Found'); header('Status: 200 Found'); header('Content-Type: image/jpg'); readfile($root.$file.'-'.$matches[2].$ext); exit; } } } } header('Content-Type: image/gif'); readfile(_PS_IMG_DIR_.'404.gif'); exit; } elseif (in_array(Tools::strtolower(substr($_SERVER['REQUEST_URI'], -3)), array('.js', 'css'))) { $this->context->cookie->disallowWriting(); exit; } parent::initContent(); $this->setTemplate(_PS_THEME_DIR_.'404.tpl'); } protected function canonicalRedirection($canonical_url = '') { // 404 - no need to redirect to the canonical url } protected function sslRedirection() { // 404 - no need to redirect } } Just found this lines // header('HTTP/1.1 404 Not Found');// header('Status: 404 Not Found');header("Location: http://prestashark.eu/"); and insert yourdomain.com instead of prestashark.eu thats all. works like a charm Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now