编程语言
首页 > 编程语言> > php – 强制Magento无路由返回状态301而不是404

php – 强制Magento无路由返回状态301而不是404

作者:互联网

我的任务是强制所有404页面返回http状态301.我一直在网上搜索/阅读,但我找不到任何有关如何完成此操作的信息.

有没有办法更改layout.xml或模板文件中的http状态?如果没有,我应该看什么控制器?

解决方法:

我没有太多关注它,但404消息似乎是在这个文件中发送 – 在3个函数中:

服务器路径:
/应用程序/代码/核心/法师/ CMS /控制器

我将标头从404更改为301重定向.可能不是最琐碎的解决方案,但似乎有效.

**/**
 * Default index action (with 404 Not Found headers)
 * Used if default page don't configure or available
 *
 */
public function defaultIndexAction()
{
    $this->getResponse()->setHeader('HTTP/1.1, 301 Moved Permanently');
    $this->getResponse()->setHeader('Location','http://www.streetcred.dk');
}
/**
 * Render CMS 404 Not found page
 *
 * @param string $coreRoute
 */
public function noRouteAction($coreRoute = null)
{
    $this->getResponse()->setHeader('HTTP/1.1, 301 Moved Permanently');
    $this->getResponse()->setHeader('Location','http://www.streetcred.dk');
}
/**
 * Default no route page action
 * Used if no route page don't configure or available
 *
 */
public function defaultNoRouteAction()
{
    $this->getResponse()->setHeader('HTTP/1.1, 301 Moved Permanently');
    $this->getResponse()->setHeader('Location','http://www.streetcred.dk');
}**

标签:php,http-status-codes,magento,http-status-code-301
来源: https://codeday.me/bug/20190716/1480826.html