OpenCart – .htaccess Configuration

This article will show you everything you need to know about how to configure your .htaccess file in Opencart. The .htaccess file plays a couple important roles.

Important Roles of .HTACCESS (as pertains to Opencart)

-Adds extra security to the framework with certain command lines. Here is an example of such lines:

# Prevent Directoy listing
Options -Indexes

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

-Enables Apache Mod Re-write to work correctly. Here is an example of that command line:

# 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]

There are also extra functions that the Opencart .htaccess file has. Here are all of the extra lines to pay attention to:

### 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 received. 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

If a line has a # sign before it then it is not active. It’s basically COMMENTED OUT. These are optional settings that you can enable if you need to. What we are really going to focus on today is the setting that pertains to the SEO URL or otherwise called APACHE MOD RE-WRITE. Opencart uses APACHE MOD RE_WRITE along with PHP to allow for all urls to become friendlier to Search Engines. This happens by turning a dynamic URL into a STATIC URL. When setting up your catalog you will find a place to enter what is called an SEO KEY WORD. This keyword will identify the item in the URL for example www.yourdomain.com/catalog/cakes/chocolate-cake chocolate cake being the Key Word. You can set this up for all of your products, category names, and certain other pages but it will not work unless you first enable the .htaccess.

Enabling the .htaccess

The .htaccess in Opencart, by default comes as a text file so it will look like .htaccess.txt In order to enable the file we need to get rid of the (.txt) at the end and rename it. The easiest way to do this is to upload it to your server and rename the file from within your FTP. For example in File Zilla you just have to right click on the file and choose RENAME.

rename

Now you need to make sure that the rewrite command is configured correctly. If you installed your Opencart in the root directory (which means it is not in a sub folder) then you will not need to do anything. If you installed in a sub directory then go to the following line and make sure it points for your sub-directory

RewriteBase / << If your sub directory is “cake” the this should read /cake

This is the basic use of the .htaccess however there are many uses that you will find later on down the road. .htaccess is powerful and can also be helpful in other types of re-writes like 301.

Looking for quality OpenCart Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , | Posted under OpenCart | RSS 2.0

Author Spotlight

Joe Stenhouse

Joe Stenhouse

I am a web application developer that specializes in PHP, JAVASCRIPT, MYSQL, HTML, and CSS. We manifest exciting potentials within the world wide web through means of innovation.

Leave a Reply

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


− 7 = 2

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