Adding SEO Friendly URL’s to OpenCart

First off, I must give credit where it is due. I got most of my information on OpenCart Clean URL’s from PHP Genious. In this post I will explain how friendly or clean URL’s work in OpenCart.

Clean URL’s are built into OpenCart 1.5. To use SEO URL’s you need to enable them under your stores server settings, rename the .htaccess.txt file and add your SEO keyword for each product and category you create. The keywords will not be created for you. You must also have Apache mod_rewrite turned on. Most web hosts will have this on by default.

First off, I must give credit where it is due. I got most of my information on OpenCart Clean URL’s from PHP Genious. In this post I will explain how friendly or clean URL’s work in OpenCart.

Clean URL’s are built into OpenCart 1.5. To use SEO URL’s you need to enable them under your stores server settings, rename the .htaccess.txt file and add your SEO keyword for each product and category you create. The keywords will not be created for you. You must also have Apache mod_rewrite turned on. Most web hosts will have this on by default.

Enable SEO URL’s in the OpenCart Admin

The first step is to enable SEO URL’s in your stores admin. Go to the “System” drop-down and click on “Settings”. Locate the store you want to alter and click the “Edit” link off to the right. Finally click the “Server” tab and set the SEO URL’s radio to “Yes” and save your settings.

Rename the .htaccess.txt file

Next you must create an .htaccess file. If you do not create this file your pages will not display. OpenCart provides a file called .htaccess.txt. Rename this file to .htaccess and you will be good to go. If you don’t have this file in your root directory you will need to make your own .htaccess file. The fiel should include the following:

# 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
 
 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
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
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

Enter SEO Keywords for URL’s

Finally, you need to enter SEO keywords for every page, information, product and category you want to have URL rewrite. You can find the field for the SEO Keywords under the Data tab when editing and creating items.

Once you have entered the SEO Keywords your URL’w will be working. Now go and enjoy more traffic and happy customers.

46 Comments

  1. Tuesday 15, 2011

    Thank you for these clear instructions. Interestingly, if you use an SEO keyword for the product only, you get a nice short URL that just has the product name after the root domain (like a WordPress post). But if you add an SEO keyword for the category, the category’s URL will be shortened and the product URL will contain both the category and the product name. Either way, this is a huge improvement on the standard set-up, and a step that a huge number of e-commerce sites seem to miss.

  2. Wednesday 21, 2011

    This is a very slick feature of opencart that can enhance your sites visibility. One thing to watch out for is creating too many category sub levels as each will add to the SEO string. I also recommend that (before going live) you really nail down what the names of your categories and products will be. If you end up making a lot of changes it will take forever for google to update, leaving you with a lot of 404 errors.

  3. Sunday 1, 2012

    Thank you so much for this. Your instructions are very clear and easy to follow.
    I didn’t have a .htaccess file and I received a 403 forbidden error after creating one. I figured the ‘Prevent direct access to files’ make all the php files inaccessible. I changed it to following to get it working.
    # Prevent Direct Access to files

    Order deny,allow
    Allow from all

    I understand what I have done could be a security risk. Is there any other way to prevent direct access to files? Thanks in Advance.

  4. Thursday 26, 2012

    I have tried this method and it didnt work. how do I enable mod_rewrite on my server. Am using MAC

  5. Kevin Dees
    Monday 30, 2012

    You may need to do a bit of googling. I tried to find something for you myself but I dont really know what version of apache or mac you are using.

  6. Sunday 12, 2012

    I tried this method but on my browser “Internal Server Error”.
    can you help me please

  7. Kevin Dees
    Sunday 12, 2012

    Be sure you have apache mod rewrite installed and + FollowSymLinks on for the Directory you are working with. See http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html and http://httpd.apache.org/docs/2.0/mod/core.html#options sadly I can not help you out side of these two things. The fix wil be dependent on the technologies you have running and that can vary.

  8. Tuesday 27, 2012

    Thank you it’s working

  9. Tuesday 24, 2012

    Your instructions were pretty good till you got the the paragraph about renaming your htaccess file.

    Why does all that text need to be in the file ?
    Some if just seems to be comments.

  10. Kevin Dees
    Tuesday 24, 2012

    The text I have in the post is the original file. this is why there are comments. If you already have .htaccess I would worry about it.

  11. Brian T.
    Friday 27, 2012

    I am using Arvixe for a hosting solution. I have implemented both your instructions and other instructions that I found at opencart.com. and I have implemented the rewrite module and have vast experience with Apache and many linux distros on my own physical boxes with no problems. However, with Arvixe it works for a few days, and then BAM! sites stop working.

    So I thought, “ok you didn’t clear you cache and it never worked in the first place.” Tried again, worked for a couple of days and revisited the sites with different VMs etc. and then a couple days go by, and BAM ‘page not available.’

    There are no errors in the logs to even give me an idea of where to start and I don’t have access to the /var/log/apache2/*

    Thoughts? Ideas? Suggestions?

  12. Kevin Dees
    Friday 27, 2012

    Sounds like you may be having DNS issues. I would recommend contacting your provider and asking about down time. This seems very odd.

  13. RJ
    Sunday 29, 2012

    The tutorial is great but I try to add the selection keywords and it gave me a 500 and error. Please help hx.

  14. Brian T.
    Monday 30, 2012

    Ok, found the issue. Multiple SEO keywords put in by the customer for every product. Nothing was unique…..

  15. Kevin Dees
    Monday 30, 2012

    If you are using Apache be sure you have mod rewrite on.

  16. RJ
    Thursday 3, 2012

    Okay good karma to you. It works. Keep up the good work….

  17. Saturday 5, 2012

    thanks!

  18. Wednesday 23, 2012

    Hi,

    “I received a 403 forbidden error on all pages after creating htaccess. I figured the ‘Prevent direct access to files’ make all the php files inaccessible. I changed it to following to get it working.
    # Prevent Direct Access to files
    Order deny,allow
    Allow from all
    I understand what I have done could be a security risk. Is there any other way to prevent direct access to files? Thanks in Advance.”

    Any solution for this issue yet? i am having the same issue and i’m worried about security of my website…

  19. Burhan
    Wednesday 23, 2012

    Hello mate,

    Have u ever found a solution for this security issue ? i’m having the same.

    Regards,
    Burhan

  20. Kevin Dees
    Wednesday 23, 2012

    you may be having these issues due to the user apache is running under and the user that has access to your files.

  21. Monday 2, 2012

    I’m working on a client;s site and followed your instructions on changing the URLs to SEO-friendly ones. However, the account and checkout links re-direct me to the front page. Can you give some input regarding this issue? I’d greatly appreciate it. Thanks!

  22. Monday 9, 2012

    I’m not sure what could be going on. I have run into this issue before.

  23. Thursday 9, 2012

    Hi
    Thanks for an informative article i hit a problem which turned out to be simple to fix
    after changing name of htaccess my site dissapeared this turned out to be caused by my host “one.com” not allowing the options command however it turned out that they had mod rewrite and followsymlinks enabled on the server so i simply removeed them from the htaccess file and it worked 1st time

  24. Sunday 19, 2012

    Hi,

    I tried to rename .htacces but still SEO friendly URls not coming. it goes to home page of website

  25. Sunday 9, 2012

    Hi,

    Thank you for this tutorial.
    I followed all the steps like you suggest. I got a 500 Internal Server Error, but I contacted my Support team and they found the solution. I see that the URLs now have the category name, however I get an 404 error message after clicking in the categories
    “The requested URL /fabricantes was not found on this server.

    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.”

    My hosting support team does not offer help on this issue. Can you suggest how do I solve this.
    Thank you so much for sharing your knowledge.

    Kind regards,
    Ricardo Moura

  26. Monday 10, 2012

    I wish I could help you here. It could be a multitude of things going on. The only thing I can think of is that you may not have clean/friendly URLs enabled server side which is very unlikely :/

  27. Monday 10, 2012

    Hum, .htaccess is a tricky one as it is also a server side issue and not always something to do with the software (OpenCart) I know this doesn’t help much.

  28. Manoj Bhardwaj
    Sunday 16, 2012

    Thanks you it’s working.

  29. Saturday 22, 2012

    I’m having trouble getting the SEO urls function to work. In your instructions you say:
    “you need to enter SEO keywords for every page, information, product and category you want to have URL rewrite. ”

    If I leave some SEO Keyword fields empty will it cause errors?.

  30. Tuesday 9, 2012

    Hi i try to follow your instructions but i get “Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.” before i remove the #
    from the orders.what do i have to do ?

  31. Tuesday 23, 2012

    Thanks for the article. I am still having trouble with SEO Url on my site. I can get them to work just fine, but when I do, once a customer logs in, and goes to another page, he is no longer appearing to be logged in except at checkout.

    Say I have a product you must be logged in to Download.
    http://www.thehonorarycitizen.com/accessories?product_id=98
    A customer logs in, and goes back to this page, Download is still not visible, as if he/she never signed in.
    This happens only when SEO Url is turned on, works fine when it is off.
    Its like the SEO Urls are creating new sessions or something.
    How can I correct this? is it a specific re-write rule I have to add in .htaccess?

    Thanks,
    T.

  32. Thursday 15, 2012

    It worked! Thanks so much!
    I have a lotta work to do now. Awesome!

  33. John Bish
    Monday 19, 2012

    Hey Kevin

    Thanks for the great guide. Managed to get this working with the help of your page. I’ve been browsing the extension store and wondering if anyone has had any experience with this mod
    http://www.opencart.com/index.php?route=extension/extension/info&extension_id=5023
    and am wondering if it’s worth adding to my website. I’ve got approximately 250 products and 20 categories

    Ricardo Moura – I had the same issue as you and it turned out to be the rewrite base in the htaccess file since I’m using /shop/ as my directory

    John

  34. Monday 19, 2012

    I have not used the module but seems like it could be helpful.

  35. Monday 19, 2012

    This sounds like an .htaccess error. You may need to do some research around that.

  36. Monday 19, 2012

    I do not think it will but it is possible since it is tied to the url structure.

  37. Monday 19, 2012

    This is probably due to a module conflict. I would try the support forms with more specific details on the opencart website.

  38. Monday 19, 2012

    hi, could anyone tell me how to enable rewrite url for tags system.
    thanks

  39. Wednesday 28, 2012

    I Had an issue with the site failing and had to comment out the
    # Prevent Direct Access to files

    # Order deny,allow
    # Deny from all
    which cured the rewrite.
    My question is how big a security hole is that and can i plug it?

    Great Article !

  40. Wednesday 28, 2012

    Unfortunately I’m not much of a security expert. It might be worth asking over at the http://stackexchange.com/sites

    Also, http://serverfault.com/ might be the one on the list to ask on.

  41. Tuesday 4, 2012

    hi we buy your opencart seo patch program but we are installing that program I have got a problem. we install your seo and I open my admin panel seo url and chanced my .htacess file but example my contact and sitemap page are don’t execute what can ı do?

  42. Sunday 30, 2012

    I’m not sure what your problem might be most of the issues I have seen here have been to do with server configurations.

  43. Sunday 17, 2013

    Nice article, but turning on SEO url option in admin, makes store very very slow. Any idea.
    Thanks

  44. Thursday 21, 2013

    I’m just starting up with opencart and you’ve solved my biggest problem.

  45. Thursday 21, 2013

    It could be your server configuration. Unfortunately, there is not much I can help with there.