Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Weird duplicated 404 request
  • Hello, I'm with a weird problem that only occurs on my production server, even if I execute the code in development mode.

    I have an Auth controller and in the before() function I check I the controller/action that I'm trying to access needs authentication.

    I added a log at the begin of this method to investigate this issue.

    So, if I try to access http://mydomain/home it checks the authentication and the request is processed without erros, but ~1sec later, my log get two 404 requests. This also happens if I manually type the 404 request that I defined in routes.php

    My logs: (The "Ok!" means that the /resource/action does not need authentication)

    Error - 2012-12-28 16:31:14 --> http://sistema.cbo.org.br/home/perfil
    Error - 2012-12-28 16:31:14 --> home
    Error - 2012-12-28 16:31:21 --> 404 OK!
    Error - 2012-12-28 16:31:21 --> 404 OK!
    Error - 2012-12-28 16:31:38 --> http://sistema.cbo.org.br/home/perfil
    Error - 2012-12-28 16:31:38 --> home
    Error - 2012-12-28 16:31:43 --> 404 OK!
    Error - 2012-12-28 16:31:43 --> 404 OK!
    Error - 2012-12-28 16:31:51 --> http://sistema.cbo.org.br/conexoes
    Error - 2012-12-28 16:31:51 --> conexoes
    Error - 2012-12-28 16:31:53 --> 404 OK!
    Error - 2012-12-28 16:31:53 --> 404 OK!

    // HERE IS THE 404 request typed manually
    Error - 2012-12-28 16:32:36 --> 404 OK!
    Error - 2012-12-28 16:32:37 --> 404 OK!
    Error - 2012-12-28 16:32:37 --> 404 OK!

    So, I can't figure out what is happening here.

  • You don't have a missing asset, or some rights issue, that causes a second rewrite to index.php?
  • I don't think so. If I return a string without using assets I have the same "error". And I'm logging inside my Auth controller, so an asset request does not go through the Auth controller.

    Same error with this action
    public function action_test()
    {
    return new Response('Hello');
    }

    And the log
    Error - 2012-12-28 17:59:14 --> test OK!
    Error - 2012-12-28 17:59:14 --> 404 OK!
    Error - 2012-12-28 17:59:14 --> 404 OK!


    And here is my Controller_Auth before function
  • HarroHarro
    Accepted Answer
    Why would your 404 action be called if the requested action (in this case 'test') exists, and is called?

    Check your webserver log to see it this is caused by external requests. When you request 'test', does that result in a single HTTP GET in your webserver log, or do you see more then one appear?

    If it's more then one, check if what is requested actually exists (and is readable by the webserver). If not, it would cause a rewrite to index.php, causing the 404. You can also capture this by logging the entire requested URI instead of only the action.

    If not, than it must be caused by your code, but I can't think of anything that could. 404's are handled in FuelPHP by throwing a HttpNotFoundException, and that doesn't easily happen by mistake. This exception is caught in your index.php, and handled there by creating a new Request for the 404 route. You haven't modified the index.php?
  • Problem solved. There was a hardcoded request to my 404 page inside the index.php. Don't ask me why...
    Thanks for your attention.
  • That should be there, it's what captures all 404 cases.

    The framework will throw a HttpNotFoundException when it encounters a 404 situation, which is then caught in your index.php, and which will fire a new request for the 404 route.

    If you remove that, you don't have 404 handling anymore.

    How are you now handling the 404 route then?
  • I know. I changed the original index.php at some time, maybe for a debug and I forgot to remove the 404 request.

    The fuel 404 handling still there. Everything is working fine now!
    Thanks.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion