I'm using Laravel 5.1. I have this in my .htaccess
file (these are only changes in the file, compared to the default):
Options -Indexes
ErrorDocument 403 /error-403
I also have a js/
directory in my public/
directory.
When I try to access the /js/
directory in the browser, I don't get the /error-403
route opened, as I'd expect. Instead I get Laravel's 404 HTTP error handler triggered (I get a 404 page from Laravel) and I don't understand why.
When I open /error-403
directly in the browser, the corresponding view opens fine. Here are some interesting server variables which I see in PHP for both of these requests.
/error-403
:
"REDIRECT_STATUS" => "200"
"REDIRECT_URL" => "/error-403"
"REQUEST_METHOD" => "GET"
"REQUEST_URI" => "/error-403"
/js/
:
"REDIRECT_REDIRECT_REQUEST_METHOD" => "GET"
"REDIRECT_REDIRECT_STATUS" => "403"
"REDIRECT_STATUS" => "403"
"REDIRECT_URL" => "/error-403"
"REQUEST_METHOD" => "GET"
"REQUEST_URI" => "/js/"
To me it seems like Apache's redirecting the request to Laravel, but Laravel, instead of picking up the URL /error-403
, picks up the URL /js/
for which no route exists and then throws a 404.
Has anyone else encountered similar problems? What am I missing here? How can I set up Laravel so that Apache (and its ErrorDocument
statement) redirects to a route defined in Laravel? And by "how", I mean how can I do it in a proper way, so it's not a hack. I guess I could create a custom middleware which would examine these server variables and correct the route, but this seems dirty and I don't know if I'm missing something here.