: Nginx 404 not working with PHP? I have a 404 file and it is working with nginx. However when I modify the 404 file to redirect the user it does not redirect. visiting http://site.com/404.php
I have a 404 file and it is working with nginx. However when I modify the 404 file to redirect the user it does not redirect.
visiting site.com/404.php redirects the user.
visiting site.com/askllj299lakj is just a blank page.
The code in the 404 file is just a header redirect,
<?php
header('Location: site.com/'); exit;
?>
Why doesn't this work in nginx?
More posts by @Gonzalez347
1 Comments
Sorted by latest first Latest Oldest Best
A redirect is by definition a 302 header code which will result in a new request. 404 error pages should never redirect anywhere as they are an end of the line code. In addition if you where to do this and redirect the user to the homepage with a 404 error that would cause all sorts of issues later on down the track as search engines would treat your homepage as a 404 not found error page.
Instead of redirecting to the homepage in this matter create a standard HTML page that says that the page the user was searching for could not be found on the server (you can play with it and make it humorous if your website is appropriate for that). On that HTML page there is nothing stopping you from redirecting the user to the homepage using...
<meta http-equiv="refresh" content="3;url=http://www.domain.com" />
Which will redirect the user to the homepage after 3 seconds. This tells the end user the page they where searching for couldn't be found and redirects the user back to the homepage and complies with all standards and doesn't cause later problems down the track.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.