Enable SEO friendly feature in Opencart

Tram Ho

“Happy new year – happy to develop all things as you want”. Hello everyone, I decided to write an article to start a new journey for the new year. This article summarizes how to enable “SEO friendly Url in Opencart” feature.

1. Summary What are SEO Friendly URLs?

First of all, we need to understand the concept of “Seo Friendly Urls”?. “Seo friendly url” or “Slug Url” is a concept used to refer to the link structure after the domain name, this structure combines with the domain name and creates a link to the website’s resources (an article). writing, a source page, images, videos…). “Seo friendly url” has the following 2 special features:

  • A string that is a combination of the characters aZ and the numbers 0-9 with the delimiter “-” representing a space or the special characters “%*~!”.
  • Slug Url character string is always clear, easy to remember and unique in all existing links in a website.

And SEO Friendly is one of the important requirements when implementing a successful SEO plan, so having the website support this feature is a must in the home-made “digital marketing and SEO” era. The content below will hopefully help you – those who are new to Opencart will have a smoother start in the future.

2. Enable SEO Friendly URLs in Opencart.

Unlike WordPress or Pretashop, by default this link beautification feature is not enabled in Opencart but must be done manually through 2 steps as follows:

2.1 Step 1: Enable SEO Urls feature in admin

  1. Login to the admin panel (you need system permissions to see the next settings).
  2. Navigate to System > Settings -> Server (System > System Configuration > Server).
  3. Check the USE SEO Urls feature in the admin as shown below. Remember to clear the system cache if you have a cache plugin installed.

2.2 Step 2: Change the .htaccess file

After completing step 1, basically your website has been activated with SEO features, every time you add a new article or a new product, in the admin section, there will be a section for you to customize the link of the resource. . However, in order for users to be able to access that link, you need to edit the htaccess file (currently on nginx, I still don’t know what the standard configuration file is, a/c/e who knows how to share me with you? ok) as follows: .htaccess file structure

To be able to add code 301 in the .htaccess file, you need to add it above the last line in this code.

3. Add SEO Friendly Urls feature to your self-created module.

By default, these Slug Urls strings are stored in a table, every time the user accesses the link, Opencart’s Core will read a record in this table and navigate to the corresponding controller. However, this feature does not automatically detech every time we add a new controller or a new module, so it needs to be activated in another way in the following 2 directions:

3.1 Case 1: Add a controller with methods as the endpoint of the view

An example for this case is that we want to add a contact page for the website to get customer information, or a landing page to run ads. Mindset for this case, we only need to create 1 controller with 1 method to display the view with the contact form combined with this content storage handle. Suppose we create a controller named “contact” with method “index” with the following directory structure:

Now we access the contact page with a link with the following pattern: root-domain/index.php?route=folder/controller/method As in the above example, it will be root-domain/index.php?route=contact-folder /contact/index or root-domain/index.php?route=contact-folder/contact with the default index method if not provided. To convert the above difficult-to-remember url into something like: root-domain/lien-he-voi-chung-toi , go to the admin and search for the item: Design > SEO URL or Design > SEO URL to add a record. into the SEO URL link manager.

Note:

  • Query will be equal to contact-folder/contact/index
  • Keyword will be equal to lien-he-voi-chung-toi

3.2 Case 2: Add a custom module with render view data dependent on model id

As in Example 3.1, the render data of the view depends on the static code added in the contact.twig file in the code. So what if we want render data to be retrieved from a model mapped from one or more tables in the database? The most visual example for this is the module for posting job advertisements on the website. This simple module has the following basic features:

  1. A page of listings of posts
  2. Each job posting on the posting page will render a detailed page of the job posting content that has been entered in the admin page.

On the list page we can create a controller and a method like in Example 3.1. The details page needs to get dynamic data from the get method on the url with a param like Tuyendung=id in the generated url.

To do this we need to add some code in the file:

  • Opencart 3 + 4: catalog/controller/startup/seo_url.php
  • Opencart 2: catalog/controller/common/seo_url.php
  • Opencart 4: update later (I haven’t touched her yet)

I sent 1 file seo_url.php after customizing and adding some SEO links. Hope the article will help you.

Share the news now

Source : Viblo