Hi all
To display custom error page, In my htaccess i have
ErrorDocument 404 http://domain.com/error.php
in the error.php my code is
<?php
header("Location:http://www.domain.com/pagenotfound.php");
?>
when any page is not found then the user is getting redirected to “pagenotfound.php” page fine.
BUT Google webmaster tool is showing these redirected(Page not found) pages under “SOFT 404 ERRORS”.
google says
The target URL doesn't exist, but your server is not returning a 404 (file not found) error
when i see the headers in firefox developer toolbar then it shows as
Request URL : http://www.domain.com/error.php
Request Method : GET
Status code : 302 Moved Temporarily
Version : HTTP/1.1
when in the htaccess “404” is defined, then why are the headers showing as “302” ??
How can i make the redirection as 404 so the errors in webmaster tool can be removed ?
How can i remove these “SOFT 404 Errors” in webmaster tool ??
Any help on this issue will be great
thanks
vineet
Why are you redirecting your 404 page? It seems an odd thing to do to me. Why not just have
ErrorDocument 404 http://domain.com/pagenotfound.php
in your .htaccess file?
1 Like
Hi gandalf458
if i remove the redirection, then will it return 404 ??
or do i need to make another change also ??
thanks
vineet
Just changing the .htacess file should be all you need.
Is your pagenotfound.php
file returning headers like
header('HTTP/1.0 404 Not Found');
* depending on your HTTP version
Hi Mittineague
No its not returning 404.
Its showing status as “302 Found” ?
How can i return header as 404 ??
thanks
vineet
If and only if your PHP Version supports this function which I believe it did not for PHP Version: 5.3
Try this:
<?php
http-response-code(404);
1 Like
vinpkl
8
hi
i added this below code in “error.php”
<?php
header('HTTP/1.0 404 Not Found');
include("error-msg.php");
?>
now when i type in the address bar
domain.com/random.php
then these are the status codes i get
random.php = 302 found
error.php = 404 not found
There is no “random.php” page on my server.
Do they both need to return 404 ??
or only one will return 404 ??
thanks
vineet
vinpkl
9
Hi all
i want to do exactly how “sitepoint.com” is doing
just type in the browser address bar
www.sitepoint.com/random.php
it will display a custom error page and also the header status will be return as “404”
can anyone tell me how to do this ??
please see the attached screenshot for reference
vineet
I answered that in post #2
vinpkl
11
i removed the redirection the same day you answered.
but its not returning 404
random.php = 302 found
error.php = 404 not found
vineet
What’s the contents of your htaccess file?
vinpkl
13
its has many rules written in it.
Can you confirm me whether i have to write absolute url for the error page or relative url without domain name ??
ErrorDocument 404 http://domain.com/error.php
or
ErrorDocument 404 error.php
Do you think absolute vs relative can be a issue ??
vineet
You probably want it relative to the root directory, eg:
ErrorDocument 404 /error.php
vinpkl
15
wow thats working now and returning 404.
But now another problem is coming
when i visit
domain.com/random.php
the page only outputs name of page as “error.php”
means i can see “error.php” written on “random.php”
the page is echoing the “page name”
how can i show the content of “error-msg.php” on this page instead of pagename ??
error.php has only 2 code lines in it
header('HTTP/1.0 404 Not Found');
include("error-msg.php");
vineet
You don’t need
header('HTTP/1.0 404 Not Found');
That’s just confusing things. The 404 not found has already been registered. It makes no sense to send that header.
vinpkl
17
ok i removed the header code
and now only 1 line is in error.php
<?php
echo "this page doesnot exists on our website !"
?>
But still it output the “page name” error.php
i still see the pagename instead of message.
how to remove page name
vineet
I can’t think what might cause your server to display the document name rather than running the PHP script.
system
Closed
19
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.