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

  • SEARCH
  • Home
  • 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 8179661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:03:07+00:00 2026-06-07T00:03:07+00:00

For CakePHP errors I know that there exists CakeError and AppError solutions. But I

  • 0

For CakePHP errors I know that there exists CakeError and AppError solutions.
But I need to make a redirection within controller.

In AppController there exists:

function afterFilter() {
    if ($this->response->statusCode() == '404')
    {
        $this->redirect(array(
            'controller' => 'mycontroller',
            'action' => 'error', 404),404
        );
    }
}

But this doesn’t create a 404 status code. It creates a 302 code.
I changed code to this:

$this->redirect('/mycontroller/error/404', 404);

But the result is same.

I added this, it didn’t work also deprecated:

$this->header('http/1.0 404 not found');

How can I send a 404 code within controller redirect ?

  • 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-07T00:03:08+00:00Added an answer on June 7, 2026 at 12:03 am

    If you want to return a 404 error, use the built in CakeError support for it:

    throw new NotFoundException();
    

    You can throw this exception from your controller and it should generate a 404 response.

    There are more built-in exceptions here.

    If you are interested in making a custom error page, then see this post.

    Otherwise, I don’t think it is possible to return a 404 header code and still redirect. Http specifies redirect status codes to be in the 300s, and this is the convention CakePHP follows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

CakePHP Newbie :) I am having trouble accessing another controller and passing that data
does anyone know if there is a VALIDATE function for a form in cakePHP
Using CakePHP, I am finding that I'm duplicating some code between controller actions. I
I know it's against MVC methodologies to use helpers in controllers, but there are
I've been reading CakePHP's 2.0 migration guide where it's stated that cakeError() has been
I'm using CakePHP 2.2.0 and I need to create one route that get this
I've worked with CakePHP 1.3, but this is my first foray into CakePHP 2.0
I know this has probably been answered as it seems a common question but
I'm super new to CakePHP so I have a feeling that I'm probably just
I am rewriting our company website in cakephp, and need to find a way

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.