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

The*_*Kid 25 php seo opencart sem

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

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

到目前为止,所有标签和SEO链接都在工作; 该命令已经完成了预期的效果.

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

的index.php?路径=普通/家庭

从URL?我是否必须在硬编码PHP文件中进行查找和替换以及风险升级,还是有另一种方法?

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

Jay*_*ord 27

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

找:

return $link;
Run Code Online (Sandbox Code Playgroud)

之前在新线上放:

$link = str_replace('index.php?route=common/home', '', $link);
Run Code Online (Sandbox Code Playgroud)

由TheBlackBenzKid编辑:如果你想要完整的SEO,只需使用这一行代替上述:

$link = str_replace('index.php?route=', '', $link);
Run Code Online (Sandbox Code Playgroud)

还要确保在商店的"管理"面板中启用了SEO URL.

  • 您添加的内容将确定路线,但这可能会产生影响.例如,首先需要在链接到新URL时将其转换回路径.其次,如果页面具有除路径之外的其他参数,会发生什么.假设您使用搜索页面,您将拥有`product/search&page = 2&query = something`,这是一个无效的网址,因此我会建议您反对上面的内容 (3认同)
  • @Umair对.这个问题是在OC2发布前两年提出的 (2认同)

Vic*_*der 7

以前的"解决方案"是错误的,因为他们正在攻击SEO URL 翻译.你想要的是处理OpenCart中的URL 生成.

让我们保持简单.去/system/library/url.php看看的public function link.用此版本替换该功能:

public function link($route, $args = '', $connection = 'NONSSL') {
    if ('NONSSL' == $connection) {
        $url = $this->url;
    } else {
        $url = $this->ssl;  
    }

    if ('common/home' == $route) {
        if ($args) {
            $url .= '?' . str_replace('&', '&', '&' . ltrim($args, '&')); 
        }
    } else {
        $url .= 'index.php?route=' . $route;
        if ($args) {
            $url .= str_replace('&', '&', '&' . ltrim($args, '&')); 
        }
    }

    foreach ($this->rewrite as $rewrite) {
        $url = $rewrite->rewrite($url);
    }

    return $url;
}
Run Code Online (Sandbox Code Playgroud)

很简单.我无法相信为什么这不是OpenCart的核心.

编辑:

我运行了一些测试,如果启用了SEO URL,则必须在其中进行一次编辑/catalog/controller/common/seo_url.php以避免出现"未定义的索引"错误.

在里面public function rewrite,替换这一行:

parse_str($url_info['query'], $data);
Run Code Online (Sandbox Code Playgroud)

有了这个:

if (isset($url_info['query'])) parse_str($url_info['query'], $data);
Run Code Online (Sandbox Code Playgroud)

现在它确实有效.

  • 这将与没有启用SEO URL的OR一起使用,并将保留查询字符串参数 (2认同)

bil*_*oah 7

我非常喜欢VictorSchröder的解决方案,因为它的简单性.谢谢!我根据他的代码mods创建了一个vQmod,以防任何人都有帮助.这是代码:

<modification>

    <file name="system/library/url.php">
        <operation>
            <search position="before"><![CDATA[$url .= 'index.php?route=' . $route;]]></search>
            <add><![CDATA[
                if ('common/home' == $route) {
                    if ($args) {
                        $url .= '?' . str_replace('&', '&amp;', '&' . ltrim($args, '&'));
                    }
                } else {
            ]]></add>
        </operation>
        <operation>
            <search position="before"><![CDATA[foreach ($this->rewrite as $rewrite) {]]></search>
            <add><![CDATA[
                }
            ]]></add>
        </operation>
    </file>

    <file name="catalog/controller/common/seo_url.php">
        <operation>
            <search position="replace"><![CDATA[parse_str($url_info['query'], $data);]]></search>
            <add><![CDATA[
                if (isset($url_info['query'])) parse_str($url_info['query'], $data);
            ]]></add>
        </operation>
    </file>

</modification>
Run Code Online (Sandbox Code Playgroud)