开发者

How to catch Apache's 403 error in PHP / Kohana?

My website is running on Kohana v3, and I have set up customized error page like below in bootstrap.php

try
{
    // Attempt to execute the response
    $request->execute();
}
catch (Exception $e)
{ 
      .... error page re-direct.
}

It works fine with 404 error.

I also have some folders that cannot be directly accessed but they have to be located under the www root. I put the .htaccess to protect these folders

# nobody can access this folder from Browse开发者_Go百科r
Deny from all

When user type in the URL in the browser to access files under this folder, an Apache 403 error will be shown in plain text like this:

Forbidden

You don't have permission to access /private_folder on this server.

I want to customize this error and handle it in Kohana. However, I find that Apache fully controls the 403 error, and does not even call the index.php under this situation.

Any idea to solve it?


Instead of using .htaccess to lock that area down, you could do it in code. PHP's header function could be used to send the 403 status.

Another approach would be to set up a custom error document for 403 errors in Apache, and point this at a script to handle the error. Refer to the ErrorDocument documentation on how to do this, but it would be something along these lines:

ErrorDocument 403 /custom_403_handler.php
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜