【问题标题】:OpenCart Change Pagination Links to SEO linksOpenCart 将分页链接更改为 SEO 链接
【发布时间】:2012-07-24 10:50:55
【问题描述】:

我正在尝试在 OpenCart 中替换我的分页。

从这里:

$pagination->url = $this->url->link('product/search', $url . '&page={page}');
// Spits out 
www.site.com/index.php?route=product/search&filter_name=QUERY&page=2

到这里:

$pagination->url = $this->url->link('product/search', $url . '&page={page}');
// Spits out 
www.site.com/search?q=QUERY&page=2

该文件位于 /catalog/controller/product/search.php(OC 1.5 第 438-444 行附近)。完整的代码块:

$pagination = new Pagination();
$pagination->total = $product_total;
$pagination->page = $page;
$pagination->limit = $limit;
$pagination->text = $this->language->get('text_pagination');

$pagination->url = $this->url->link('product/search', $url . '&page={page}');
$this->data['pagination'] = $pagination->render();

【问题讨论】:

  • 这是个好问题,期待看到答案。
  • 我不确定你想在回答中看到什么。 nginx 配置?
  • 我想看看 OpenCart SEO 格式 - 我基本上不想要 index.php?route= 部分 - 真的与 Nginx 无关。

标签: php nginx preg-replace str-replace opencart


【解决方案1】:

我假设您有一个 .htaccess 文件设置,并且您已经在使用 OpenCart 1.5 中内置的 SEO。如果没有,这里有一些很好的说明:Adding SEO Friendly URL’S to OpenCart by Kevin Dees

这是部分破解,但如果您只想修复分页,它应该可以工作。

首先,您需要在我之前引用的 .htaccess 文件中添加 3 行。在这行之后:

RewriteRule sitemap.xml /index.php?route=feed/google_sitemap

添加:

RewriteCond %{QUERY_STRING} q=([^&]*) [OR]
RewriteCond %{SCRIPT_FILENAME} .*search$
RewriteRule search$ /index.php?route=product/search&filter_name=%1 [L,QSA]

因此,.htaccess 文件的所有部分应如下所示:

RewriteBase /
RewriteRule sitemap.xml /index.php?route=feed/google_sitemap
RewriteCond %{QUERY_STRING} q=([^&]*) [OR]
RewriteCond %{SCRIPT_FILENAME} .*search$
RewriteRule search$ /index.php?route=product/search&filter_name=%1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

接下来你需要修改/catalog/controller/product/search.php来生成正确的url。我注释掉了生成链接的行并在其上方添加了我自己的 2 行(您需要将 http://www.example.com 替换为您自己的信息):

$pagination = new Pagination();
$pagination->total = $product_total;
$pagination->page = $page;
$pagination->limit = $limit;
$pagination->text = $this->language->get('text_pagination');

$url = preg_replace("/filter_name/","q",$url);
$pagination->url = "http://www.example.com/search?".$url."&page={page}";
//$pagination->url = $this->url->link('product/search', $url . '&page={page}');

$this->data['pagination'] = $pagination->render();

资源:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-11
    • 2019-06-20
    • 1970-01-01
    • 1970-01-01
    • 2017-09-29
    • 2017-08-06
    • 2020-06-11
    • 1970-01-01
    相关资源
    最近更新 更多