php - 强制 Magento 没有路由返回状态 301 而不是 404

标签 php magento http-status-code-301 http-status-codes

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

有没有办法改变 layout.xml 或模板文件中的 http 状态?如果不是,我应该查看哪个 Controller ?

最佳答案

我没有仔细研究它,但 404 消息似乎是在这个文件中发送的 - 在 3 个函数中:

服务器路径: /app/code/core/Mage/Cms/controllers

我将 header 从 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 - 强制 Magento 没有路由返回状态 301 而不是 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10817449/

相关文章:

PHP MySQL UPDATE导致错误

php - 具有差异突出显示的 PHP 中的文本版本控制

mysql - 在 Magento 自定义模块中编写数据库查询

redirect - 如何对基于 Ajax 的 URL 使用元刷新?

php 301 redirects 实际上做的是 302 redirect

PHP header 重定向 301 - 有什么影响?

php - 限制 Woocommerce 结账时使用的优​​惠券数量

magento - 如何解决错误 SSL23_GET_SERVER_HELLO :sslv3 alert handshake failure

php - 更新产品属性的更有效方法,Magento

php - GET 请求 - 无法从数据库执行 SELECT 语句