OpenCart: Clean SEO URL’s for Contact Us, Site Map and other custom pages

Over the last few weeks I have been working with OpenCart, a free Open-Source Shopping Cart. And so far I have been loving it!

However it was not long until I hit a road block with the software, after enabling the clean SEO URL’s feature and setting up my “SEO Keywords” for all my products, categories and information pages. I soon realised there was no options to set this up for the Contact Us, Sitemap and various other pages!!

I soon figured it out though, and I will explain how to do this for the contact us and site map pages below:

First modify /catalog/controller/common/seo_url.php

add:

//custom SEO url's
if ($url[0] == 'contact') {
 $this->request->get['route'] = 'information/contact';
} 
if ($url[0] == 'sitemap') {
 $this->request->get['route'] = 'information/sitemap';
}

 

after:

if ($url[0] == 'information_id') {
 $this->request->get['information_id'] = $url[1];
}

 

Now you need to insert two URL aliases into your url_alias table with the following values:

 

Column:  Value: 
 query  contact=contact
 keyword  contact
 query  sitemap=sitemap
 keyword  sitemap

 

Congratulations! It is that simple! You can now link to http://yoursite.com/contact or http://yoursite.com/sitemap.

All you need todo now is repeat the steps above to create URL aliases for any page in open cart.

Facebooktwitterredditpinterestlinkedinmail
Author: Dean WilliamsI'm a Web Developer, Graphics Designer and Gamer, this is my personal site which provides PHP programming advice, hints and tips

Post Tags:
, , ,
0 0 votes
Article Rating
Subscribe
Notify of
34 Comments
Inline Feedbacks
View all comments

Thanks for this you're a boss!

Thanks for this, it's exactly what I'm looking for...

although I've got a slight problem with it - it works fine in that I can use mysite.com/contact to reach the contact page but the system generated urls such as in the footer and in the breadcrumbs are still of the form:

mysite.com/index.php?route=information/contact

just wondered if you had a fix for this?

Just a quick update to my last comment,

adding:

} elseif (isset($data['route']) && $data['route'] == 'information/contact') {
$url .= '/contact';

just before the line:

} elseif ($key == 'path') {
$categories = explode('_', $value);

In /catalog/controller/common/seo_url.php@rewrite() seems to do the trick

Nice write up. Could you, perhaps, go into a little explanation on how the URL relates to the controller/table mapping?

For example, if I wanted the URL to be "/contact-us" instead of "/contact", what bits in the seo_url.php and url_alias table would get changed?

Cheers!

Hi there, firstly thank you for posting this. Unfortunately am having some troubles with it and is not working for me. Maybe you could help me out? i added this part: if ($url[0] == 'contact') { $this->request->get['route'] = 'information/contact'; } if ($url[0] == 'sitemap') { $this->request->get['route'] = 'information/sitemap'; } but not this as it was already in there: if ($url[0] == 'information_id') { $this->request->get['information_id'] = $url[1]; } - See more at: http://deano.me/2013/07/opencart-clean-seo-urls-for-contact-us-site-map-and-other-custom-pages/#sthash.orsgovZ9.dpuf so this part still is in the file. Finally i went to my db on table: url_alias and added: sitemap=sitemap as query and keyword as sitemap. But still… Read more »

By the way, this is how it looks in my file in general,:

if ($url[0] == 'manufacturer_id') {
$this->request->get['manufacturer_id'] = $url[1];
}

if ($url[0] == 'information_id') {
$this->request->get['information_id'] = $url[1];
}
if ($url[0] == 'contact') {
$this->request->get['route'] = 'information/contact';
}
if ($url[0] == 'sitemap') {
$this->request->get['route'] = 'information/sitemap';
}

Hello Deano I have followed your instructions as described above. But on my side the custom urls doesn't work. And if add a new information text in opencart are they just normal text. E.g. i want to add "my account like this but with a nice url: http://matrix.nicolette.ro/index.php?route=account/account. And if I set "account" in opencart/Catalog/Information then appears just a normal text?! How is it possible to change from .../index.php?route=account/account to .../myaccount? Here you can see my code [seo_url.php] : config->get('config_seo_url')) { $this->url->addRewrite($this); } // Decode URL if (isset($this->request->get['_route_'])) { $parts = explode('/', $this->request->get['_route_']); foreach ($parts as $part) { $query =… Read more »

Excellent post, but just wondering where I edit the url_alias table? Am very new to OC and still finding my feet.
Many thanks !!

Hi thnx for sharing

it works gud when i type mystore.com/contact to show the contact page but urls such as in the footer and in the breadcrumbs are still of the form:

mystore.com/index.php?route=information/contact

mystore.com/contact -- i want this type when i click

Hey Deano, plz help me to create sort url, what you have write not working in OC 1.5.6.1

Hi there,

I'm able to follow everything except the location of url_alias table. I would appreciate any help. Thanks!

Great job mate! You saved my day! :)

Hi Mr.Daeno,

am having some troubles with it and is not working for me.
still have mystore.com/index.php?route=information/contact

but i want like this: mystore.com/contact-us

Great Working !!!

Thanks Dean

Dear Dean,

I don't know why but I can't get it working for siteŁ http://www.wilek666.vot.pl/index.php?route=information/o-firmie.
I'm using oc 1.5.6.1

I add to seo_url.php:
if ($url[0] == 'o-firmie') {
$this->request->get['route'] = 'information/o-firmie';
}

and to table oc_url_alias
INSERT INTO oc_url_alias (query, keyword) VALUES ('o-firmie=o-firmie', 'o-firmie');

Could you help me ?

Thank you ! Works just fine !
Congrats

how can i change url "https://mysite.com/index.php?route=account/return/insert" to https://mysite.com/return. please help

Thank U for such a helpful post. it really helped me. i want to re-write search page. can you please help?

Opencart 2.x it is not working for me.

If you want contact-us instead of contact then
seo_url.php
if ($url[0] == 'contact-us') {
$this->request->get['route'] = 'information/contact';
}
url_alia
query contact-us=contact-us=contact-us=contact-us
keyword contact-us=contact-us