OpenCart is built initially on apache servers. This the most popular HTTP server. It is free and opensource and still holds around 50% of the market share. So if you just purchased a hosting account you are probably using apache by default.


Quick Tip!

You can setup your SEO Urls with SEO Module with a click of a button. Go to SEO Module / Dashboard and activate quick setup for SEO Urls.

Remember that this will activate SEO Urls per store. If you have multi store, you will need to switch to another store to activate the SEO urls there.


What is .htaccess and how does it work in OpenCart?

.htaccess is a configuration file that allows you to make changes to your apache server per-directory. When the file is placed in a directory, apache uses these configurations and applies them to that directory and all the subdirectories in it.

.htaccess is commonly used for these 4 tasks:

  1. Mod_rewrite - you can set rules to tell your server how treat the urls of your website and what content should be returned to the user. In other words you can rewrite the urls to make them user-friendly.
  2. Authentication - you can use .htaccess to set a username and password to access a required directory with the help of .htpasswd
  3. Custom Error pages - a very useful feature that helps you setup a custom error page for 400 or 500. OpenCart covers the 404 yet it is still a good idea to set a custom Error page for the rest of the server errors.
  4. Redirects - used to setup redirect rules. Often used when changing from http to https.

There are much more you can do with .htaccess yet these are the most popular in OpenCart with the first being the most important.

OpenCart uses this file to add SEO Urls. By default OpenCart carries a file in the root folder named .htaccess.txt with the required directives. Unless you remove the .txt extension by renaming the file, it will not take any effect on the work of your apache server.


How to activate SEO Urls in Opencart with .htaccess?

.htaccess editor allows you to modify your apache .htaccess file directly from the admin panel. To activate your SEO Urls you need to the following:

  1. rename .htaccess.txt to .htaccess
  2. go to OpenCart Store settings / tab server and activate SEO URls


If .htaccess is missing

You can create the file manually.

  1. Create a file in the root folder of your OpenCart store and name it .htaccess
  2. Paste the .htaccess rules, provided 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 +SymLinksIfOwnerMatch
# Prevent Directoy listing
Options -Indexes
# Prevent Direct Access to files

Require all denied
## For apache 2.2 and older, replace "Require all denied" with these two lines :
# 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=extension/feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=extension/feed/google_base [L]
RewriteRule ^system/storage/(.*) 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


Heads up!

If your store is located in a subfolder (ex. http://myshop.com/store/) then you are required to edit the defualt RewriteBase from RewriteBase / to RewriteBase /store/ in your .htaccess file.


Robots.txt Editor
Robots.txt is used by search bots as recommendations before indexing your website....
Leave a comment