banner



How To Change Route Url In Opencart

Read Time: vi mins Languages:

In the class of this tutorial, we'll go through the details of custom SEO-friendly URLs. It'south an important attribute yous should expect at while developing custom modules, and information technology affects the overall search engine rankings every bit well.

Nosotros'll use the latest version of OpenCart, so make sure that you've installed that to follow the lawmaking.

What We Are Going to Practise—in a Nutshell

Here's a summary of the steps we'll need to accept to achieve custom URLs in OpenCart:

  • Start, we volition need to empathise how it works in the cadre.
  • We'll become through the changes required in the core files.
  • We'll have a quick wait at the SQL queries to insert our custom URL mappings.
  • Nosotros'll cover how to use congenital-in rewrite functions.

Then, that'due south the quick glance of what's coming up adjacent. Let's motility on to the showtime topic.

The URL Mappings in a Database

First of all, information technology'due south important to understand how SEO URLs work in the core of OpenCart.

Go alee and explore the entries in the "url_alias" MySQL table using phpMyAdmin or something similar. You'll see mappings similar this.

There are two important columns to notation here. The kickoff one is thequery column which stores the actual path, and the other is keyword, which stores the SEO alias for that URL.

As you can see, there are mappings for different entities like product, category, information, and manufacturer. Whenever whatever entity is saved in the back-cease of OpenCart, an associated entry is added to this table.

In the front end-end, whenever the user accesses the URL, OpenCart finds the related mapping from the "url_alias" table. In this fashion, the actual entity is mapped to the SEO-friendly URL.

Go ahead and open the file catalog/controller/common/seo_url.php, and permit's explore the following snippet from the index method.

As y'all can see, we are fetching the associated entry from the "url_alias" tabular array. After that, the query parameter is parsed and an associated internal path is returned.

So, this is the mode it works in the core. Unfortunately, the setup only works for core URLs—for custom URLs we need to alter the core code. That's the recipe of our next department.

The Core File Changes

Go ahead and open the file catalog/controller/common/seo_url.php, and supplant the rewrite method with the following ane.

The rewrite method is used to convert an internal URL into an SEO-friendly URL. Simply information technology does this just for internal URLs. Hence, nosotros need to add custom code to get in work for our custom modules as well. In our lawmaking changes, we have provided the last else case which loads the mapping for our custom module. We have not added our custom mapping yet, so let's exercise information technology in our next section.

Although we have modified the core file directly, it's just for the sake of simplicity. You should utilize OCMOD to alter the cadre file without really modifying it.

Add MySQL Entries

In this section, nosotros will add an SEO URL mapping for our custom module. Once again, it'southward a plain SQL for example purposes—you tin achieve that using module install scripts.

Go ahead and run it in your OpenCart database.

In the adjacent and final section, we will see how to use the helper role to produce SEO-friendly links.

How It Works

Go ahead and create a new file catalog/controller/custom/custom.php with the following contents.

Now, in the front-end, open up the URL http://www.yourstore.com/index.php?route=custom/custom.

Yeah, it's a plain white screen just with i link, and that is what nosotros intended. The of import thing to note here is the URL of that link— it'southward now SEO-friendly! Click on that and it will load the same page, as we have added the mapping for that in the "url_alias" table.

And then, that'southward the whole concept demonstrated in a unproblematic way. You could extend it and make a model to insert SEO-friendly links for your custom module.

Conclusion

Today, we have discussed an important topic in OpenCart—custom SEO-friendly URLs. We took a very simple approach to explain information technology, and I hope that it was useful for y'all.

If yous're looking for additional OpenCart tools, utilities, extensions, and so on that you tin can leverage in your own projects or for your own instruction, don't forget to see what we have available in the marketplace.

Feel complimentary to postal service your queries and suggestions using the feed below.

Did you discover this post useful?

Source: https://code.tutsplus.com/tutorials/how-to-rewrite-custom-urls-in-opencart--cms-25734

Posted by: pattersonackwoure.blogspot.com

0 Response to "How To Change Route Url In Opencart"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel