# Custom 404 and error page

**URL:** <https://discourse.laminas.dev/t/custom-404-and-error-page/3117>\
**Category:** Components & MVC\
**Tags:** laminas-mvc\
**Created:** [December 2, 2022, 7:25am UTC](https://discourse.laminas.dev/t/custom-404-and-error-page/3117 "2022-12-02T07:25:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ebuddy](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ebuddy/32/1536_2.png) [@ebuddy](https://discourse.laminas.dev/u/ebuddy)\
**Post date:** [December 2, 2022, 7:25am UTC](https://discourse.laminas.dev/t/custom-404-and-error-page/3117/1 "2022-12-02T07:25:14Z")

</div>

Hello I would like to know if someone has any code snippet for customizing 404 not found and error pages ?

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [December 2, 2022, 8:53am UTC](https://discourse.laminas.dev/t/custom-404-and-error-page/3117/2 "2022-12-02T08:53:50Z")

</div>

Maybe I misunderstood something, but you can modify the existing view scripts:

> **[laminas-mvc-skeleton/module/Application/view/error at 1.4.x ·...](https://github.com/laminas/laminas-mvc-skeleton/tree/1.4.x/module/Application/view/error)**
>
> 1.4.x/module/Application/view/error

Do you mean this?

---

<div class="post-metadata">

**Author:** ![ebuddy](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ebuddy/32/1536_2.png) [@ebuddy](https://discourse.laminas.dev/u/ebuddy)\
**Post date:** [December 2, 2022, 3:51pm UTC](https://discourse.laminas.dev/t/custom-404-and-error-page/3117/3 "2022-12-02T15:51:51Z")

</div>

Yes. But I would like to create another view for error and 404 not found. And perhaps on bootstrap, catch these errors and show the appropriate view.

---

<div class="post-metadata">

**Author:** ![mwcode](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/mwcode/32/1148_2.png) [@mwcode](https://discourse.laminas.dev/u/mwcode)\
**Post date:** [December 6, 2022, 9:07am UTC](https://discourse.laminas.dev/t/custom-404-and-error-page/3117/4 "2022-12-06T09:07:47Z")

</div>

You can add on Module.php something like this code:

```auto
 public function onDispatchError(MvcEvent $event)
    {
        $response = $event->getResponse();
        if ($response->getStatusCode() == 404) {
            $event->getViewModel()->setTemplate("layout/404");
        }
    }

```

In the view-file you can create a custom design

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [December 6, 2022, 9:11am UTC](https://discourse.laminas.dev/t/custom-404-and-error-page/3117/5 "2022-12-06T09:11:35Z")

</div>

> [@mwcode](#):
>
> You can add on Module.php something like this code:

This is not necessary as it is already set in the configuration:

> <https://github.com/laminas/laminas-mvc-skeleton/blob/f37963bc531028c47464c92be07fb9897637cb4c/module/Application/config/module.config.php#L45-L46>

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [December 6, 2022, 9:12am UTC](https://discourse.laminas.dev/t/custom-404-and-error-page/3117/6 "2022-12-06T09:12:50Z")

</div>

> [@ebuddy](#):
>
> …another view for error and 404 not found

Do you want multiple designs for 404 or other errors?

---

<div class="post-metadata">

**Author:** ![mwcode](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/mwcode/32/1148_2.png) [@mwcode](https://discourse.laminas.dev/u/mwcode)\
**Post date:** [December 6, 2022, 9:24am UTC](https://discourse.laminas.dev/t/custom-404-and-error-page/3117/7 "2022-12-06T09:24:43Z")

</div>

Oh, I thought he meant an extra layout for the 404-Page.

---

<div class="post-metadata">

**Author:** ![lon9man](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/lon9man/32/1314_2.png) [@lon9man](https://discourse.laminas.dev/u/lon9man)\
**Post date:** [August 25, 2026, 11:56am UTC](https://discourse.laminas.dev/t/custom-404-and-error-page/3117/8 "2026-08-25T11:56:46Z")

</div>

> [@froschdesign](#):
>
> Do you want multiple designs for 404 or other errors?

hello, i am interesting in how to change default to the different 404-page per some action/module or other edge case?

thanks!

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [August 29, 2026, 10:48am UTC](https://discourse.laminas.dev/t/custom-404-and-error-page/3117/9 "2026-08-29T10:48:04Z")

</div>

It’s been a long time, unfortunately, but perhaps by overwriting the controller plugin `CreateHttpNotFoundModel`. There you can set the template on view model.

> <https://github.com/laminas/laminas-mvc/blob/53ba28b7222d3a3b49747a26babef43d1b17fb6f/src/Controller/Plugin/CreateHttpNotFoundModel.php>

* * *

> **Caution**  
> The **laminas-mvc** components are considered feature-complete and are in _security-only maintenance mode_ [until the security support for PHP 8.4 ends](https://getlaminas.org/blog/2026-03-06-laminas-mvc-eol-schedule.html), which will be 31st December 2028.  
> The [Mezzio](https://docs.mezzio.dev/) and [Laminas Components](https://docs.laminas.dev/components) are still in active development.
