OpenCart Change Pagination Links to SEO links

I am trying to replace my Pagination within OpenCart.

From this:

$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

to this:

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

The file is in /catalog/controller/product/search.php (OC 1.5 near line 438-444). The full block of code:

$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();

Answers


I am assuming you have a .htaccess file setup and you are already using the SEO built into OpenCart 1.5. If not, here are some pretty good instructions: Adding SEO Friendly URL’S to OpenCart by Kevin Dees

This is a partial hack, but if all you want to fix is the pagination, it should work.

First you need to add 3 lines to the .htaccess file I referenced earlier. After this line:

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

Add:

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

So in all that section of the .htaccess file should look like:

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]

Next you need to modify the /catalog/controller/product/search.php to generate the correct url. I commented out the line that generates the link and added my own 2 lines above it(you'll need replace http://www.site.com with your own info):

$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.site.com/search?".$url."&page={page}";
//$pagination->url = $this->url->link('product/search', $url . '&page={page}');

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

Resources: I found some of the basics of RewriteRules from: RoScripts.com Pretty URLs - a guide to URL rewriting. Here's an example of how to pull from the query string from a blog comment by Nidaan here. And finally for everything else regarding apache's mod_rewrite visit: Apache Module mod_rewrite

Good Luck! And God Bless!


Need Your Help

TypeError parsing JSON obj from urllib ipython

python ipython urllib

I am using an API to request data from a website. The data can be found here and pasted into a JSON Viewer. My code along with the error that it is returning are below. I am guessing that this is a...

Random "GROUP" of radiobutton?

android radio-button

How can i Random "GROUP" of radiobutton?