OpenCart Support Services

Want to extend your store, edit or create new designs, add custom features or fix broken ones for your OpenCart store? We offer a range of development and SEO services. Click here to get in touch

Create SEO Friendly URLs for OpenCart Pages

By Jack
In OpenCart
Apr 17th, 2013
31 Comments
109656 Views

Hi everyone, in this blog post I will be addressing a very common issue with OpenCart which has bugged me for a while but I’ve only recently looked into it. OpenCart has a very handy SEO-Friendly function which allows you to specify the URL on product, information and category pages but it has no option for the core pages within OpenCart.

For example, the standard homepage URL in OpenCart is:

www.[DOMAIN NAME].com/index.php?route=common/home

Hardly useful, although a common workaround would be to just use the domain name as the homelink without the filename. However, the contact page is at:

www.[DOMAIN NAME].com/index.php?route=information/contact

which does nothing for user experience. So in this blog I will be showing you how to change these URLs to something easier for users(to something like www.[DOMAIN NAME].com/contact, each URL change is a two step process as shown below:

  1. Edit the .htaccess file to create a unique rule for the page URL
  2. Change which URL OpenCart redirects users to when using the site

Preparation

OK, so the first thing to do is download the .htaccess file which is in the root folder of your OpenCart store and open it up in a text editor such as Notepad++. When you open it up you will see something like the default .htaccess code as shown below:

# 1.To use URL Alias you need to be running apache with mod_rewrite enabled. 

# 2. In your opencart directory rename htaccess.txt to .htaccess.

# For any support issues please visit: http://www.opencart.com

Options +FollowSymlinks

# Prevent Directoy listing 
Options -Indexes

# Prevent Direct Access to files
<FilesMatch ".(tpl|ini|log)">
 Order deny,allow
 Deny from all

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/ 

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base  [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

### Additional Settings that may need to be enabled for some servers 
### Uncomment the commands by removing the # sign in front of it.
### If you get an "Internal Server Error 500" after enabling any of the following settings, restore the # as this means your host doesn't allow that.

# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
# php_flag register_globals off

# 2. If your cart has magic quotes enabled, This may work to disable it:
# php_flag magic_quotes_gpc Off

# 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try
# php_value upload_max_filesize 999M

# 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value post_max_size 999M

# 5. set max time script can take. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_execution_time 200

# 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_input_time 200

Your store will also need to have SEO-Friendly URLs turned on in the settings menu which you can reach through the admin panel.

Changing The Contact Us Page URL in OpenCart

Right, so in this example we will be changing the OpenCart contact us page to something more obvious to users as shown below:

www.[DOMAIN NAME].com/index.php?route=information/contact

will change to

www.[DOMAIN NAME].com/contact

to do this we will build an extra ReWrite rule and add it to the .htaccess file. I’ll go through what this new rule does exactly here:

RewriteRule  ^contact/?$  index.php?route=information/contact  [L]     #Contact Page
  • Red Section – This is the part where we declare it is a rewrite rule and what the rule should look for. The ^ symbol marks the start of the search string and the $ marks the end of the string. I have added the /? to allow the end slash or not meaning users can write either …/contact or ../contact/.
  • Green Section – This is the part which tells the .htaccess file what to change the URL to if it finds the string highlighted in the Red Section. This is the default contact page URL as I’m sure you’ve noticed :)
  • Blue Section – This is a simple part which tells the .htaccess file that it should stop processing rules after this one. If you remove this section you will most likely get a server 500 error, so leave it in.

Now, this ReWrite rule just tells to change the URL if someone types in www.[DOMAIN NAME].com/contact and pull up the normal contact page. It works just like the other ReWrite rules except it isn’t using the database so just add it to your .htaccess file so it looks something like this:

# 1.To use URL Alias you need to be running apache with mod_rewrite enabled. 

# 2. In your opencart directory rename htaccess.txt to .htaccess.

# For any support issues please visit: http://www.opencart.com

Options +FollowSymlinks

# Prevent Directoy listing 
Options -Indexes

# Prevent Direct Access to files
<FilesMatch ".(tpl|ini|log)">
 Order deny,allow
 Deny from all

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/ 

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base  [L]
#NEW REWRITE RULES
RewriteRule    ^contact/?$    index.php?route=information/contact  [L]  #Contact Page
#END NEW REWRITE RULES
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

### Additional Settings that may need to be enabled for some servers 
### Uncomment the commands by removing the # sign in front of it.
### If you get an "Internal Server Error 500" after enabling any of the following settings, restore the # as this means your host doesn't allow that.

# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
# php_flag register_globals off

# 2. If your cart has magic quotes enabled, This may work to disable it:
# php_flag magic_quotes_gpc Off

# 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try
# php_value upload_max_filesize 999M

# 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value post_max_size 999M

# 5. set max time script can take. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_execution_time 200

# 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_input_time 200

Upload it to your root OpenCart folder and then try it. If you type www.[DOMAIN NAME].com/contact it will show up the normal contact us page! Hurrah!

Unfortunately, we’re not quite done yet. We need to change the links in OpenCart to point to the new contact us page URL rather than the old one so I’ll go through a few of them but bear in mind that there might be some I’ve missed you’ll need to check.

Open up the following file in your text editor:

  • catalog/view/theme/[YOUR THEME]/template/common/footer.tpl

Find and replace the following:

  • <a href=”<?php echo $contact; ?>”><?php echo $text_contact; ?></a>
changes to
  • <a href=”http://www.[DOMAIN NAME].com/contact”><?php echo $text_contact; ?></a>

This changes the contact us link at the bottom of the page. The next file will change the contact page link shown to users to have successfully checked out.

  • catalog/language/[YOUR LANGUAGE]/checkout/success.php

Have a look for the section in both of the top two lines where it tells the user to direct questions to the store owners, in that line you will see a link which needs changing as below:

<a href="%s">

changes to

<a href="http://www.[DOMAIN NAME].com/contact">

which changes the other link.

There will be other references to the contact us page but you can leave a comment below and I will tell you which files you need to be editing to make them point to your new URL!

Changing The Account Page URL in OpenCart

OK, another URL which everyone would like to see edited is the account page. So, I’m going to go through the steps again just to show you how it applies in this case. You could probably guess what the .htaccess rule is going to be but I’ll add it below anyway:

RewriteRule ^account/?$    index.php?route=account/account  [L]  #Account Page

In this rule we are using www.[DOMAIN NAME].com/account as the link to the account page and calling index.php?route=account/account when the .htaccess file sees it in the URL. Nice and easy.

This one is slightly different though, we need to go into the login function and change the URL to which the system redirects when a user successfully logs in. I have a blog post which details the process of redirecting customers after logging in and out so I will just write the basic steps in this one.

Open up the following file:

  • catalog/controller/account/login.php

and find the following line and replace it for the link you want to use as shown below:

$this->redirect($this->url->link('account/account', '', 'SSL'));

changes to

$this->redirect('http://www.[YOUR DOMAIN].com/account')

And there we go, we’ve changed the account link for the OpenCart store to something more obvious for users. You can have more than one unique .htaccess rule if you want to use multiple links so your filw will look like this:

# 1.To use URL Alias you need to be running apache with mod_rewrite enabled. 

# 2. In your opencart directory rename htaccess.txt to .htaccess.

# For any support issues please visit: http://www.opencart.com

Options +FollowSymlinks

# Prevent Directoy listing 
Options -Indexes

# Prevent Direct Access to files
<FilesMatch ".(tpl|ini|log)">
 Order deny,allow
 Deny from all

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/ 

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base  [L]
#NEW REWRITE RULES
RewriteRule  ^contact/?$  index.php?route=information/contact  [L] #Contact Page
ReWriteRule  ^account/?$  index.php?route=account/account  [L]  #Account Page
#END NEW REWRITE RULES
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

### Additional Settings that may need to be enabled for some servers 
### Uncomment the commands by removing the # sign in front of it.
### If you get an "Internal Server Error 500" after enabling any of the following settings, restore the # as this means your host doesn't allow that.

# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
# php_flag register_globals off

# 2. If your cart has magic quotes enabled, This may work to disable it:
# php_flag magic_quotes_gpc Off

# 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try
# php_value upload_max_filesize 999M

# 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value post_max_size 999M

# 5. set max time script can take. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_execution_time 200

# 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_input_time 200

So, there we go

By now you’ll be familiar with the principles of changing the base URLs for core OpenCart pages. The hard work is finding all of the links and pointing them in the right direction but as I mentioned earlier just leave me a comment if you want any help finding the right files to edit. Below are a full list of URL changes written as .htaccess:

#NEW REWRITE RULES
ReWriteRule  ^home/$  index.php?route=common/home [L] #Home Page
RewriteRule  ^contact/?$  index.php?route=information/contact  [L] #Contact Page
ReWriteRule  ^account/?$  index.php?route=account/account  [L]  #Account Page
ReWriteRule  ^login/?$  index.php?route=account/login  [L]  #Login Page
ReWriteRule  ^logout/?$  index.php?route=account/logout  [L]  #Logout Link
ReWriteRule  ^cart/$  index.php?route=checkout/cart  [L] #Cart Page
ReWriteRule  ^checkout/$  index.php?route=checkout/checkout  [L] #Checkout Page
ReWriteRule  ^manufacturers/$  index.php?route=product/manufacturer  [L] #Manufacturer Page
ReWriteRule  ^specials/$  index.php?route=product/special  [L] #Specials Page
ReWriteRule  ^vouchers/$  index.php?route=account/voucher  [L] #Voucher Page
ReWriteRule  ^wishlist/$  index.php?route=account/wishlist  [L] #Wishlist Page
ReWriteRule  ^my-orders/$  index.php?route=account/orders  [L] #Past Orders Page
#END NEW REWRITE RULES

Well, this is a mammoth post and I hope you found it useful. Let me know how you get on and ask any questions you like by leaving me a comment below as usual!

Posted By

Has 70 Posts

The founder of Cart Advisor, is an eCommerce developer specialising in OpenCart development and content SEO. Based in Lincoln, UK, Jack has worked with hundreds of businesses and runs his own company Destrove which offers OpenCart Development, OpenCart Theme Design and more.

31 Responses to “Create SEO Friendly URLs for OpenCart Pages”

  1. Hi…I’m still building and have a lot of loose ends.
    I found the above post this morning, and it is just the info I was looking for….another issue solved..thanks again !

  2. Tom says:

    Hi Jack,
    I have a question before amending my code to reflect these changes.
    Will it work the same if you have multiple stores?
    Thanks

    Tom

    • Hi Tom,

      Good question, I believe it will work the same for all stores yes, it just rewrites the URL which will stay the same regardless of the language or store selected.

      Cheers,

      Jack

  3. Saru says:

    Hello Jack,

    One quick mention:

    RewriteRule ^contact/?$ index.php?route=information/contact [L]

    After that, you would have two live url’s with the same info (duplicate).

    http://yoursite.com/contact
    and
    http://yoursite.com/index.php?route=information/contact

    For the moment the only solution I see for this is to declare the canonical url as the http://yoursite.com/contact

    I have opened up the catalog/controller/information/contact.php, and around line 9, just after:

    $this->document->setTitle($this->language->get('heading_title'));

    I have added:

    $this->document->addLink(str_replace('index.php?route=','',$this->url->link('contact')), 'canonical');

    Maybe there is other elegant way to do it but for the moment I would use this working patch.

    Regards and looking for your next move :)

  4. Sunny says:

    Hi i have used your approach to change the url of contact but unfortunately i am getting below error
    “The page you requested cannot be found!”

    URL : http://www.tayalcomputers.com/contact

    Plz tell me how can i rectify this.

    • Jack Davis says:

      There could be a few reasons for this:

      Is mod_rewrite enabled on your server? .htaccess.txt renamed to .htaccess? SEO URLs enabled in OpenCart settings?

      Also check that there is no typo in the .htaccess file, I fell into that one at some point haha!

      Cheers,

      Jack

  5. Chris says:

    Sunny – if your OC install is in a subfolder (www.yoursite.com/shop for example) then you need to amend a line in the .htacess file:

    RewriteBase /

    Would become:

    RewriteBase /shop/

    That was what gave me all those 404 errors!

    Hope that helps!

  6. Sunny says:

    Jack,

    Is mod_rewrite enabled on your server? YES
    .htaccess.txt renamed to .htaccess? YES
    SEO URLs enabled in OpenCart settings? YES

    thats why other information pages are working like http://www.tayalcomputers.com/about-us etc.

    These are the things which have been added in .htaccess

    RewriteRule ^contact/?$ index.php?route=information/contact [L] #Contact Page
    RewriteRule ^account/?$ index.php?route=account/account [L] #Account Page

    Please let me know what went wrong.

    Thanks: Sunny

  7. Sunny says:

    Chris ,
    No it is installed in root folder(i.e. www) so not point giving this error.

    Is above process working for you ?

    Regards,
    Sunny

  8. Bruce A says:

    I went to .htaccess file and found there are o bytes in my .htaccess.

    My problem ismy customers cannot type the letter p into shop cart forms on my website.

    I found this when I was trying to do seo and was directed to htaccess.

    can you help me?

    • Jack Davis says:

      Try downloading OpenCart again from opencart.com and taking the .htaccess file from there and uploading to your store. Should work a treat, not sure why it would be 0 bytes, issue with installation/unpacking the OpenCart files etc? Also, you might want to get in touch with your web host and make sure that they support .htaccess rewriting as well

      Thanks,

      Jack

  9. Leigh says:

    Hi Jack, I followed the steps for changing the Account page URL, but now whenever I click on My Account, I am instead redirected straight back to the Homepage (ie. index.php). I can’t access the Account login/registration page anymore. Is there any reason why this is happening? How can I fix it? Thanks!

  10. Chris says:

    Sunny,

    It worked for the 2 extra information pages I had added in which my automatic SEO vqMod would not work for – that fixed most of them though so I am using both methods at present.

    Still have one module which is not working for SEO Urls but I am going to ask the author…

    Regards,

    Chris

  11. Shazma says:

    Hi Jack,
    I have done the URL rewrite for my website. But google analytics show many duplicated tags dure to different urls for same product.
    Eg:

    /Delivery-Information
    /index.php?route=information/information&information_id=6

    Will this effect my SEO? Looking forward to your response. :)

    • Jack Davis says:

      Hi Shazma,

      This is just Google being pedantic I think, OpenCart adds a canonical link which tells Google which one should be indexes as the original but although Webmaster Tools shows all the variations I wouldn’t worry about it.

      Thanks,

      Jack

  12. dangkhoa says:

    thanks for your post
    I have the problem:

    I want to rewrite index.php?route=account/order to my-order

    then I change it in htaccess as you said

    $this->redirect($this->url->link(‘account/order’, ”, ‘SSL’));

    changes to

    $this->redirect(‘http://www.[YOUR DOMAIN].com/login’)

    PROBLEM IS when I visit http://www.domain.com/my-order IT DOESN’T WORK, PAGE NOT FOUND

    Pls help
    thanks

    • dangkhoa says:

      I mean these change is in controler

      $this->redirect($this->url->link(‘account/order’, ”, ‘SSL’));

      changes to

      $this->redirect(‘http://www.[YOUR DOMAIN].com/login’)

    • Jack Davis says:

      Hi,

      Could you send over the text you used in the .htaccess file for the ReWrite rule?

      Cheers,

      Jack

  13. Monika says:

    Dear Thanks a lot.
    Your bright ideas helped me a lot in my full site http://www.mtjcart.com

    I changed a lot of things from your Suggestions.

    Somewhere I sticked up also. After some brainstorming that also sorted out.

    In Account link to change I have changed the Account login page.

    I found completely white page. Is it due to cache ?? I havent checked by removing chache from my browser.

    Thanks and suggest

  14. Rob Allport says:

    Hi,

    Nice idea. Having lots pog rewrite rules does slow down your site. Why not match the url pattern. E.g.


    RewriteRule ^account/(.*)$ index.php?route=account/$1 [L]

    That will match all account type urls (there are lots …) and save lots of time :)

    Rob

  15. Einius says:

    Hi, Jack.
    I have same issue just like Sunny..

    mod_rewrite enabled on your server? YES
    .htaccess.txt renamed to .htaccess? YES
    SEO URLs enabled in OpenCart settings? YES
    I`m not using any sub servers or smth… Files is in root folder, and other SEO URLs works just fine. (categories, products, etc…) except these (which should be edited after your guide…).
    Maybe you have any suggestions to solve my issue?

    Best regards, Einius

  16. Bodi says:

    Hi,

    I created a custom page and put it in the information directory

    http://cryptojeweler.com/index.php?route=information/expo

    I added the .htaccess line

    RewriteRule ^expo/?$ index.php?route=information/expo [L]

    but it doesn’t work.

    I’m noticing people are talking about changing something in the controller, but I have no “redirect” line in my echo.php controller file.

    Suggestions?

    • Jack says:

      Have you placed this after the ReWrite Engine On line in htaccess?

      Is it showing a 404 error or showing a different page?

      Thanks,

      Jack

  17. Emiel says:

    Hi there Jack!

    You really helped me a lot but I still got things not working..
    My contact page got now a clean url ‘domain/contact’ but I followed the stept to change my account page but it didn’t work for me.
    When I click on my account or type in my browser ‘domain/account’ the page is not found..

    Can you help me out?

    Emiel

    • Jack says:

      Hi Emiel,

      Have you ensured that your .htaccess.txt file is renamed to .htaccess (without the “.txt” at the end)?

      Thanks,

      Jack

  18. Armando says:

    Hello Jack

    I have followed the instructions on creating the SEO URL for my contact us page in open cart and i seem to get the double URLS that SARU mentioned. I also tried his patch or work around to make the URL work and it still does not work. I removed everything to go back to the normal URL and I still have the double url in my browser. I have been trying to fix this with no solution. What can I do?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>