Opencart v3 SEO URLs

OpenCart 3.x comes with an easy to enable SEO URLs, from the OpenCart admin. I had a couple of issues getting this working properly, here’s what I did;

Step 1:

  • Login to your OpenCart admin panel.
  • Navigate to System > Settings and click the Action “Edit” link.
  • On the “Server” tab, set “Use SEO URL’s” to “Yes” and save the changes.

Step 2:

We need to now tell the web server what to do with our SEO options;

  • OpenCart provides a file called .htaccess.txt in the install directory. Rename it to .htaccess. If you have already created a .htaccess file, add this code at the end of the file:

# SEO URL Settings

RewriteEngine On

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^system/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) [NC]
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

Note: if you have installed your OpenCart in a sub directory then you will need to change the RewriteBase directory to reflect this;

RewriteBase /

RewriteBase /subdirectory/

Step 3:

So, you’re good to go. You can now add SEO keywords to your Category and Product definitions, remember they need to be unique and must not contain spaces, use a ‘-‘ to separate multiple words.

  • Navigate to Categories or Products and click the Action “Edit” link next to the Category or Product you want to update.
  • On the “SEO” tab, add a unique keyword  and save the changes.

Step 4:

At this point your SEO should be working but you may notice that many of the links in the footer have original style links and are not SEO links.

You could find a plugin to do the remainder but I didn’t;

As an example here is how to change the Contact Us and Return URLs

  • Edit the following file;

/catalog/view/theme/<themeName>/template/common/footer.twig

  • Locate the following lines

<li><a href=”{{ contact }}“>{{ text_contact }}</a></li>

<li><a href=”{{ return }}“>{{ text_return }}</a></li>

  • Replace the RED bracketed code between the ” ” with the SEO keyword you want.

<li><a href=”contact-us“>{{ text_contact }}</a></li>

<li><a href=”returns“>{{ text_return }}</a></li>

  • Now we need to tell the web server to reWrite the new SEO rules specifically. Edit you .htaccess file and add the following lines after your ReWriteBase line.

RewriteBase /
RewriteRule ^contact-us$ index.php?route=information/contact [L]
RewriteRule ^returns$ index.php?route=account/return/add [L]

  • The BLUE URL is what you will see if you hover over a footer link or in the browser address bar if you click a link. Take everything after you website name i.e. http://<websiteName>/index.php?route=account/return/add

One last thing would be to refresh the OpenCart cache. You do this from your admin dashboard by clicking the top right settings icon then click the theme refresh icon

 

Leave a Reply

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