Wednesday 3 June 2015

How To Turn On SEO Friendly URLs In OpenCart


In this blog post I will be showing you how to activate the SEO Friendly URLs in your OpenCart store. Although it is very quick, for newcomers to the software and those who are less technical (and a bit nervous of FTP) it seems to be a stumbling point and ends up being added to the OpenCart Forums. So here I will go through the steps and give you a blow-by-blow on exactly what you need to do.

Rename your OpenCart .htaccess.txt file

OK, so the first thing we are going to do is the one thing which gets new developers and store owners all mixed up. If you open up your website folder in FTP, or navigate to your Web Host file manager, you will see there is a file there called “.htaccess.txt” (without the quotes). The file is named like that by default for servers which don’t support the URL Rewriting or for those who don’t want to use it. In order to start rewriting URLs we need to change the name of that file to remove the “.txt” section and ensure that the server stops thinking it is a text file and knows it is a .htaccess file really.
Simply right click in FTP and select rename. Then, just remove the last four characters of the file name so that the new name is: “.htaccess”.



For stores installed in a subdirectory

OK, so if your store is installed on a root folder of a domain, ignore this section. So if your OpenCart website is installed on say: www.examplewebsite.com/opencart then you will need to make a further change, so that the .htaccess file knows to add on the extra section otherwise it will link of to the wrong places and cause you much hair loss. In the following example I will assume that I am changing the .htaccess file for my OpenCart store installed on www.mywebsite.com/store.
Open up the .htaccess in your favourite text editor (if you try to download the file through FTP and it disappears, change the name back to “.htaccess.txt” while you edit it then upload and remove the extension again). Find the section which looks like:



# 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]
The bit we need to edit is the RewriteBase section, here you would simply add in the rest of the domain name after the root folder. In my example, I would put:
# If
your opencart installation does not run on the main web folder make
sure you folder it does run in ie. / becomes /shop/ 

RewriteBase
/store/
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]



Always remember to put a “/” at the end, no matter what you put otherwise it will not add it in and links won’t work as they should. You just replace store with the name of whatever folder OpenCart is installed in. If your store is in a second, third or (God forbid) fourth subdirectory, just keep adding them in until it is the right path (e.g. store/opencart/customer-store/).

Change Your OpenCart Settings To Automatically Use SEO URLs

So the next thing to do is go to your OpenCart settings menu and tell the system that you want it to start using the SEO keywords associated with products/categories/pages etc rather than the default links. To do this, login to your OpenCart admin panel and go to: System->Settings->Edit->Click the “Server” Tab. The top option should be the one named “Use SEO URL’s”, simply flick that to Yes and click Save.

And that’s it, quick and simple guide to getting it done. Remember, you will need to define the SEO URL’s yourself by going into any OpenCart product, category, page etc admin page and setting the SEO keyword. If you are still getting 404 errors at this point then get in touch with your Web Host and ensure that they have mod_rewrite installed on the server and you are able to use it with your hosting package. Feel free to leave a question or comment below as normal!


No comments:

Post a Comment