Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Ability to specify response code on controller plugin redirect #313

Open
jroedel opened this issue Jul 13, 2019 · 2 comments
Open

Ability to specify response code on controller plugin redirect #313

jroedel opened this issue Jul 13, 2019 · 2 comments

Comments

@jroedel
Copy link

jroedel commented Jul 13, 2019

I have changed my routing setup on a production app, and I would like to provide search engines with the information that a new URL format is being used. For this I would like to use code 301 (Permanently Moved) instead of 302 (Found).

Code to reproduce the issue

In a controller action:

return $this->redirect()->toUrl('https://github.com'); //, ['statusCode' => 301]);

Expected results

I should be able to specify a statusCode of choosing

Actual results

The browser receives a 302 response code always.

Thanks for all your support!

@froschdesign
Copy link
Member

There is an open todo in the class of the redirect plugin:

* @todo allow specifying status code as a default, or as an option to methods

In the meantime you can use this workaround in any controller action:

public function indexAction()
{
    $response = $this->getResponse();
    $response->getHeaders()->addHeaderLine(
        'Location',
        'https://github.com'
    );
    $response->setStatusCode(301);
    
    return $response;
}

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-mvc; a new issue has been opened at laminas/laminas-mvc#4.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants