开发者

PHP redirect a 503 without URL change

what I do is some URL parsing at the very top of my picture page, b开发者_Python百科efore outputting anything:

foobar.com/pictures.php/2134613514/nice-sunset

If that goes wrong for any reason, I want to send the user to my error page.

For 404, 403 etc. I redirect to that same page using .htaccess, which is easy:

ErrorDocument 401 /error.php?e=401
ErrorDocument 402 /error.php?e=402
ErrorDocument 403 /error.php?e=403

So what I do in pictures.php is:

try
{
    // parse PATH_INFO, grab image from db, ...
}
catch (Exception $e) // if that goes wrong for any reason
{
    whack_error_to_log( $e );
    header("Location: /error.php?e=503");
    exit();
}

What buggers me is, that the user will see foobar.com/error.php?e=503 as the url, I would rather like him to see foobar.com/pictures/2134613514/nice-sunset, because ideally that URL will come back up, once I found the error...


try this:

try
{
    // parse PATH_INFO, grab image from db, ...
}
catch (Exception $e) // if that goes wrong for any reason
{
    whack_error_to_log( $e );
    $_GET['e'] = 503;
    include 'error.php';
    exit();
}

its a hack, but it should work


Include the script file instead of redirecting to it:

whack_error_to_log( $e );
$_GET['e'] = '503';
include 'error.php';
exit();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜