Redirect users from 404 page after 5 seconds

mkerala2

Network license
Beta tester
Joined
Jun 30, 2014
Messages
459
Points
105
We have to remove certain images from website for variety of reasons. However, there might be significant traffic coming to the image we removed and will be seeing the static 404 page without any ads.

To leverage these traffic hitting 404 pages, a adding a php redirect would drive them to website homepage or any other page.

Redirect users from 404 page after 5 seconds

After line 1 of file /app/themes/Peafowl/views/404.php, add below code

Code:
<?php if(!defined('access') or !access) die('This file cannot be directly accessed.');
header("HTTP/1.1 301 Moved Permanently");
header('Refresh: 5;url=http://yourdomain.com');
?>
Now edit the default messages displayed as follows
Code:
<div class="content-width">
    <div class="page-not-found">
        <h1><?php _se("Image doesn't exist"); ?></h1>
        <p><?php _se('The image you are looking was not found. You will be redirected in 5 seconds.'); ?></p>
        <?php if(CHV\getSetting('website_search')) { ?>
Upload new 404.php file to /app/themes/Peafowl/overrides/views
 
Last edited:
  • Like
Reactions: tobi116

Rodolfo

Chevereto Developer
Chevereto Staff
Joined
Oct 7, 2008
Messages
16,680
Points
237
Location
Chevereto HQ
Website
rodolfoberrios.com
I'm not sure which http status code is sent when you issue a redirect using header() and omitting the response code, but make sure that is 301.

You should do a 301 redirect because Google could penalize you because of sneaky traffic.
 

mkerala2

Network license
Beta tester
Joined
Jun 30, 2014
Messages
459
Points
105
I'm not sure which http status code is sent when you issue a redirect using header() and omitting the response code, but make sure that is 301.

You should do a 301 redirect because Google could penalize you because of sneaky traffic.
Thanks for the in put. I am very bad at SEO. Added
header( “HTTP/1.1 301 Moved Permanently” );
 
  • Like
Reactions: Rodolfo

ashkir

Core license
License owner
Joined
Feb 14, 2016
Messages
363
Points
125
I like this. I changed the 404 message say ing you do not have access. Google Adsense will hit you and ban you for having too many 404s. :(
 

Oakley

Network license
Beta tester
Joined
Feb 27, 2017
Messages
268
Points
78
404's are a fact of website life which Google accepts. However, what they most definately don't like is Adsense appearing on actual 404 pages. Basically Adsense should not appear on any "non-content-based" pages.

Adsense policy:

"Publishers are not permitted to place ads on any non-content based pages like thank you, error, login or exit pages."