从 OpenCart 中删除 index.php?route=common/home

新手上路,请多包涵

我目前在 OpenCart Admin User SEO URL's 设置为 Yes。

System -> Settings -> Store -> Server -> User SEO URL's

到目前为止,所有标签和 SEO 链接都可以正常工作;该命令已达到预期效果。

但是对于主页和其他一些链接;如何删除:

index.php?route=common/home

从网址?我是否必须在硬编码 PHP 文件中进行查找和替换并进行风险升级,还是有其他方法?

(没有臃肿的性能,即没有糟糕的业余工具,如 vQmod)

原文由 TheBlackBenzKid 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1k
2 个回答

要简单地删除它,您可以在 /catalog/controller/common/seo_url.php 中进行基本替换

寻找:

 return $link;

新行之前放:

 $link = str_replace('index.php?route=common/home', '', $link);

由 TheBlackBenzKid 编辑:如果您想要完整的 SEO,只需使用此行而不是上面的行:

 $link = str_replace('index.php?route=', '', $link);

还要确保在商店的管理面板中打开了 SEO URL。

原文由 Jay Gilford 发布,翻译遵循 CC BY-SA 3.0 许可协议

在 Opencart 3 中,如果你想重定向所有丑陋的 url,比如

index.php?route=common/home
index.php?route=account/register
index.php?route=product/product&path=244&product_id=481

您需要将漂亮的网址添加到 Admin -> Design -> SEO Urls 类似于

在此处输入图像描述

然后执行以下操作:在 catalog/controller/startup/seo_url.php ,在功能 index 之后

if ($this->config->get('config_seo_url')) {
   $this->url->addRewrite($this);
}

添加这个

if (isset($this->request->get['route'])) {
    if (DOMAIN_ROOT . $this->request->server['REQUEST_URI'] != $this->rewrite(DOMAIN_ROOT . $this->request->server['REQUEST_URI'])) {
        $this->response->redirect($this->rewrite(DOMAIN_ROOT . $this->request->server['REQUEST_URI']));
    }
}
elseif (strpos($this->request->server['REQUEST_URI'], 'index') !== false) {
    $this->response->redirect(HTTPS_SERVER);
}

添加最后一步是在 DOMAIN_ROOT config.php

define('DOMAIN_ROOT', 'https://www.somedomain.org'); // no slash, no subfolder

它对我来说效果很好

原文由 Gabriel Vasile 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题