One url for multiple pages


We are converting a new site from openCart to OctoberCMS, but I’ve got a problem with URLs and SEO.
SEO gurus tell to preserve all the URLs, but the problem is that openCart is using one URL for the brand page, product page and category page.

How can this be possible with octoberCMS?
The problem is that every page is using other component a I cannot programatically add/remove components for a page.

What I need to do:

One page url :/brand-slug [with brand components]
Second page url: :/product-slug [with product components]
Third page: :/category-slug [with category components]

Is there a pre-router (midleware) or router to find the right model from slug and select the right page?


You can do it logically.

In your database table:

Separate slugs with type of slug
For example:

Table columns


category-slug can be of type category. In the same table you can have one to one relation with the table contain the details of that slug.

This way when the page life cycle executes it will give you the type of the slug.

Now you can have the cases in your logic and separately load the components.

Hi this isnt the issue - I know how to select the right type of slug, the problem is in page (themes/theme/pages/everythning.htm)file:

url = "/:slug"

I can in onStart() method, find the right slug type, but I dont want to include all components in one page, becouse they will fail. I need to add/remove components in onStart() method, or in router.php find the right slug a render and specific page.

Yes that what i meant.

You can use

onRun method and then include only components in this method rather than adding in the viewBag.

1 Like

Can you please provide me an example of code, because, I cant figure it out how to do it.
This is my code in page (themes/[theme]/pages/everything.htm):

title = "All pages"
url = "/:slug"
layout = "default"

function onInit() {
    $this->addComponent(\Offline\Mall\Components\Product::class, 'product',['product'=>$slug]);


But It doesnt work, component is not loaded.

Sorry its working, the component class URL was wrong…

1 Like