SEO friendly URLs in OpenCart without modifying .htaccess or extension

Posted by on Jan 22, 2013 in Opencart ·

The URLs play a very important role in SEO. I don’t know about old versions of OC, but in 1.5.X onward, OC too has SEO friendly URLs facility.

I read on many blogs about OpenCart’s SEO URLs. I found some coding for modification of .htaccess file or usage of extensions. But I want all the OpenCart users to know that SEO URLs are possible without performing any of these actions. Also you don’t need to perform any mod or coding.

Just perform these steps..

Enable .htaccess file

By default, OpenCart comes with “.htaccess.txt” file. Simply rename it to “.htaccess” . DON’T modify anything inside that file.

By default, the .htacess file should contain :

# 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
</FilesMatch>

# 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]
RewriteRule ^download/(.*) /index.php?route=error/not_found [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

# 7. disable open_basedir limitations
# php_admin_value open_basedir none

In case you have installed OpenCart in a directory, you have to make one modification in .htaccess . Find this line in it – RewriteBase /. Make it – RewriteBase /your-directory-name.

So, if I run Opencart on www.mywebsite.com, I will simply rename the .htaccess.txt file to .htaccess.
And, if I run OpenCart on www.mywebsite.com/store, I will rename the file as well as change the line to RewriteBase /store.

Enabling SEO URLs in OpenCart

SEO URLs are turned off by default. We have to enable them first.

1. Go to Admin Panel -> System -> Settings.

2. Click on “Edit” link on the right side of the store name.

Store Settings

3. Click on “Server” tab. You will find an option – “Use SEO URL’s”. Click on “Yes” in front of it. Save the options.

Enabling SEO URLs in OpenCart admin

Adding SEO slug for products

Now we have to add SEO keyword (or slug) for each product.

1. Go to Catalog -> Products. Click on “Edit” on the right side of the product which you SEO URL for.

2. Click on the “Data” tab.

Adding SEO URL for a product in OpenCart

3. You will find one field named “SEO Keyword:”. Enter the desired link keyword there. The URL of your product will be storelink/keyword.

Do not include spaces and capital letters in it. It will make your URLs difficult to be handled. Also, while browsing, you will see the URLs like storelink/category1/category2/keyword. But the default canonical link will always be storelink/keyword. This will help search engines to include the proper product URLs instead of /index.php?route=product/product&product_id=51.

Please share your views at the comment form below.

Last updated on : December 27, 2013.

74 Comments on “SEO friendly URLs in OpenCart without modifying .htaccess or extension”

  1. Hi Animish! I was delighted to see if your solution works. In my case it didn’t. You may take a look at my website and see that I had to disable seo url because I started getting 404

    1. Hello Imran!

      The solution works perfectly as it is inbuilt feature of OpenCart. You seem to be having problem with .htaccess file.
      By default OpenCart names the file as “.htaccess.txt”. Make it “.htaccess”. Do not modify any content inside it.

      Should you face any problem again, please let me know.

  2. Hi,

    It disturbs the css of my website when i change the RewriteBase / thing. But if i wont change it according to my directory the SEO Url doesn’t works but when i do the CSS got disturbed. Can you explain it why it happens.?

      1. # 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 / clients/BP
        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

        # 7. disable open_basedir limitations
        # php_admin_value open_basedir none

    1. Hi!

      If you are getting 500 error, look at the these lines of the .htaccess code : “# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on”….

      Try removing one or more “#” after each numbered line.

      For example,
      # 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

      Make it
      # 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

      If this also doesn’t work, please contact the OpenCart Community.

  3. i resolved the problem by commenting the following lines in the htaccess file:

    #Options +FollowSymlinks

    and

    #Options -Indexes

    Now it works fine. Don’t know really why those lines did. Hope i will have no problems in the future 🙂

  4. Now i have the following behavior: for the same product i have two links. For example: in one category it have the link: cumpara.it/Monitor-LED-AOC and another category has the link: cumpara.it/Monitoare/Monitor-LED-AOC

    Do you know any quick solution? Thanks:)

    1. Hello!

      I know this happens in OpenCart. The only solution to this problem is to use canonical URLs.

      I saw your website. It is already using the canonical tag. Even if you visit “http://cumpara.it/Monitoare/Monitor-LED-AOC” , it says search engines that the main page is “http://cumpara.it/Monitor-LED-AOC” only. So you don’t need to worry about the duplicate content issue.

      (Another tip – Use only lower case letters in URLs, so that the link system would work even finer.)

  5. Dear Animish,

    i am trying to generate seo url’s on my new website. I am using a directory inside public dir. But I am getting an error. My .htaccess.txt is renamed to .htaccess. Please help me in this regard.

    1. Hello Shakeeb!

      I think you haven’t read the topic “Enable .htaccess file” on this post.

      Change the line RewriteBase / to RewriteBase /your-directory-name.

  6. Hi, just to let you know that using this appraoch including the commenting out of #Options +FollowSymlinks and #Options -Indexes worked fine for me. Thanks for your help. Ian.

  7. I have rename htacacess file .
    i have also done setting from admin
    but still its not working

    i m running it on localhost with xamp server

    1. Hello Parth!

      In your .htaccess, try making following change –
      Find this line – RewriteBase /
      Change it to –
      RewriteBase /your-directory-name

  8. Hi Animish!

    Great tut, I followed your instructions and the OC site of my cliente runs now like a charm with SEO enabled, thanx!

    I’m a Magento developer but I have a client with an OC site, and I’m surprised with OC capabilities. This is lighter and powerful, when I’ll have some xtra time I’ll be back to learn even more about it.

    Best

  9. Hi Animish,
    Whats the meaning your-directory-name? If i have 2 domain and patch, how to make it? My domain is teeha.my and teeha.com.my.

    Thanks for your help.

    1. Hello Gadaffi!

      If you run OpenCart on teeha.my, simply rename the .htaccess.txt file to .htaccess.
      If you run your store at something like teeha.my/shop, your-directory-name will be shop here.

      It looks like you have redirected teeha.com.my to teeha.my which is very fine. You do not need to take any extra efforts.

      Regards 🙂

      1. I dont have .htaccess.txt file in my cpanel? or .htaccess.
        If i tick yes in my setting, my link will broken.

        1. In this case, create a new file names .htaccess and then paste the above given code in it. (I have updated this post with the .htaccess code).

    1. Hello Syed!

      This is a common problem in OpenCart. But there is no any need to worry.

      Because, even if you go to “http://maycart.in/index.php?route=product/product&product_id=53”, OC creates a canonical URL tag containing “http://maycart.in/Leather-Note-Pad” as the main link. So, Google will not treat these links as duplicate content and index only “http://maycart.in/Leather-Note-Pad”.

      Regards 🙂

  10. Hi Animish,

    My still facing page not found error.done with all solution provided.
    Its working fine on local server.
    I have all my files in “httpdocs” folder, I wrte rewrite base/httpdocs n this worked fine in local server, but not working on live server.
    seriously in trouble, kindly help

    Kindly help.

    1. Hello Yamini!

      As it is working fine on the localhost, there must be a problem with your web host. Try contacting your web hosting provider.

      Regards 🙂

  11. Hello Animish

    I have the problem with website on the peak hours its goes really slow also when i test the website its shows Leverage browser caching is that ok to do this

    1. Hello Jay!

      It is highly recommend to leverage browser caching. I have already shared how to leverage browser caching.

      Moreover, you will have to enable server-side caching to reduce the server load and make your site lightening fast. However, this task is not that easy with OpenCart. You might need to buy an OpenCart extension.

      Regards 🙂

  12. Hi,

    I followed the procedure as mentioned above…the SEO URL’s work fine for the products but they do not work for the Home Page, Contact Page and Specials Page….how do i rectify this?

    1. Hi Nupur!

      You are basically talking about the information pages in OpenCart.

      For SEO URLs for information pages, go to Catalog -> Information. Then click on the edit link in front of any information page. You should find SEO Keyword box there. This where you can set your SEO URLs.

      I hope this helps 🙂

  13. I have read all the comment and try one by one.
    non of it helps me.

    After enable the SEO in opencart setting.
    When i click on my product, the URL is shown the correct product URL, but lead me to page 404.

    Please advice me how to fix this. thank you.

    1. Hello!

      The problem may arise due to absense of mod_rewrite on your server. Please contact your web hosting provider regarding this issue.

      Regards 🙂

  14. can you help me.
    i have .htaccess like
    RewriteRule ^index.html$ /index.php [QSA]
    RewriteRule ^pdf/.* /a-single.php [QSA]
    RewriteRule ^ebook/.* /a-single-e.php [QSA]

    output:
    /pdf/post-title-id.pdf
    /ebook/post-title-id.pdf
    and i want to change those to
    post-title-id.pdf
    post-title-id.pdf

    help me please

    1. Hello Chairul!

      Better you ask this question on the OpenCart Support Forum. Those people will help you with the proper solution.

      Regards 🙂

  15. Hi,
    Could please guide us as to how to add ALT tags to images in opencart via the admin panel. Also thanks for your guide on updating products with seo key words.
    Regards

  16. Hi Animish,

    I’ve followed every step and comments and have no luck. It keep giving me the same forbidden error page. Can you please help me with what I might be doing wrong or if I’m missing something. Thank you very much.

    Regards,
    Mary

  17. Hi there,

    There isn’t .htaccess file in my ftp root folder and when I manually make one and copy to my ftp -still nothing. Anyone, please help. By the way – do I really need this file?

    Thank you in advance

    1. Hi Greg!

      You definitely need .htaccess file if you are on Linux based hosting. Try using the cPanel directly, instead of FTP. Or contact your web hosting provider.

      Regards 🙂

  18. Brother i have done this on local host (Wamp)
    If SEO URL’s are on, server says Url can’t found.
    Please help me what should i do
    Regards

    Yahya

  19. I can see a .htaccess & .htaccess.txt file. what can I do now? I can’t rename the .htaccess.txt because there is already a .htaccess file.

    1. Simply edit the existing .htaccess file. A]Copy the code from htaccess.txt to this file.

      If you are unable to access .htaccess file, ask your web host about it.

  20. Hi Animish,

    I am using OpenCart 2.0 for the first time and just setting the Use SEO URLs to Yes and renaming .htaccess.txt to .htaccess gives me;
    Not Found – The requested URL /laptops/new-laptops was not found on this server.

    Have you any experience of this yet?

    1. Hi!

      The main reason behind this problem could be mod_rewrite not active on your server. Try contacting your web hosting provider about the same.

  21. Hello

    I am Using opencart 2.0.. I try all of the above steps; when i choose seo friendly url YES and i click on any product it will show proper url but content in page same as home page… Not Showing Perticular Product… And if i chosse No it will show proper result.

    Please Help me to Solve this problem.

    1. Hello!

      There must be something wrong with the server configuration. I would suggest you to ask about your problems on OpenCart community forum.

  22. Hi

    I have followed the instructions totally and all works fine…..until i try to login to my opencart admin! When i try to login it just goes straight back to the admin login screen again, the username and password are correct as there are no warning messages, would you know what might be causing this as its only happened since updating and enabling the .htaccess file?

    1. .htaccess may give problems if not configured properly. Make sure you have the latest .htaccess file code. If the error still doesn’t go, try asking for the help on the OpenCart community. You will definitely get quality help from there.

Leave a Reply