Reputation: 575
I have a custom 404 error page in my root.
I have edited my .httaccess file also.
Now I want to redirect to my custom 404 page,if certain condition fails in my page.
For example $_SESSION[log]==1 fails. So my question is
1.What code should I use in php to do so?
2.how to I make other types of error,like 401 and many other types of errors?
In my .httaccess page,I have these lines
ErrorDocument 404 http://mydomain.com/404custom.php
And I have a 404custom.php designed to my needs..Simple HTML page...
Upvotes: 0
Views: 155
Reputation: 10085
Don't send a Location header in error cases. Send the correct status code instead. You must send the correct status code according to the http specification.
header("HTTP/1.0 404 Not Found");
For showing the correct custom site, you have already your ErrorDocument statement in the .htaccess file.
Especially for the 403 unauthorized error sending the correct status code is important, so the browser can react accurate.
Upvotes: 2
Reputation: 118
1- To redirect your user you can use :
<?php
header('Location: http://www.example.com/404.html');
?>
But you must not send any data before using header()
no echo
and not even blank space.
2- For other errors :
ErrorDocument 400 /var/www/errors/index.html
ErrorDocument 401 /var/www/errors/index.html
ErrorDocument 403 /var/www/errors/index.html
ErrorDocument 404 /var/www/errors/index.html
ErrorDocument 500 /var/www/errors/index.html
Upvotes: 1