Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8382509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:56:38+00:00 2026-06-09T16:56:38+00:00

I am struggling a little bit while trying to display a custom 404 error

  • 0

I am struggling a little bit while trying to display a custom 404 error page using the Silex micro-framework.

My project is configured as follows:

  • got an index.php page to run in production mode, loading a prod.php configuration file
  • got an index_dev.php to run in debug mode. It uses also the prod.php configuration file, but some settings gets overridden by a dev.php file, like $app['debug'] being set to true.

So basically the configuration is the same.

I have defined an error handler as follows:

$app->error(function (\Exception $e, $code) use ($app) {

    // commented for testing purposes
    /*if ($app['debug']) {
        return;
    }*/

    if ($code == 404) {

        $loader = $app['dataloader'];
        $data = array(
            'global' => $loader->load('global'),
            'common' => $loader->load('common', $app['locale']),
            'header' => $loader->load('header', $app['locale']),
            'footer' => $loader->load('footer', $app['locale'])
        );

        return new Response( $app['twig']->render('404.html.twig', array( 'data' => $data )), 404);
    }

    return new Response('We are sorry, but something went terribly wrong.', $code);

});

When trying to access http://localhost:8888/index_dev.php/my-non-existing-page, I get my 404 template rendered and displayed as expected.

When trying to access http://localhost:8888/my-non-existing-page, my 404 template is not rendered and I get a standard 404 error page instead !

Might be difficult to help me. Feel free to ask for more details if needed. I am simply willing to understand better what is actually happening here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:56:39+00:00Added an answer on June 9, 2026 at 4:56 pm

    You will need to rewrite requests to your index.php file. See below for a basic example to get this working.

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L,QSA]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I am struggling a little with the Unit test framework... what I am
I'm brand new to Moq (using v 4) and am struggling a little with
I've been struggling with getting a working regular expression for a little project of
I've been struggling with this issue for a little while now. Found several posts
I'm trying (or rather struggling) to create a little Blackjack game. After some JavaScript
I am struggeling a little bit with some options for linking on a project
I'm helping someone fix a VB application but struggling with a little bit of
I am struggling a little bit with the concept of deferred binding and/or dependency
I'm trying to write a game using F# and Silverlight and am struggling a
I’m struggling a little bit with some XAML syntax I hope someone can advise

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.