Rectangle 27 0

apache .htaccess show 404, 403, 500, ... pages via php?


//Custom 403 errors
ErrorDocument 403 your-path/403.php

//Custom 404 errors
ErrorDocument 404 your-path/404.php

//Custom 500 errors
ErrorDocument 500 your-path/500.php

Please add an explanation of what the above has to do with the question asked. How does it relate to the requested .htaccess file?

Sorry, but such approach redirect user on error to related php page, I need to display an error on the go.

This is what you need. You can make these pages act exactly as you're asking - for eample they can all be symlinked to the same file which inspects the env vars (e.g. $_SERVER) to figure out which error to display.

Note
Rectangle 27 0

apache .htaccess show 404, 403, 500, ... pages via php?


ErrorDocument 404 /404.htm
if($_GET['code'] == '404') {
    include('404.php');
}

Change that to error.php?code=404 and then pick that up in error.php using:

When you reference an error page in .htacess, all your doing is a redirect:

Note