Develope SEO friendly URLs Plugin?


Hi :slight_smile:

I’m searching a plugin to handle SEO friendly URLs into database. I look into plugin directory but I don’t find any plugin for CakePHP 3.x.

Now I want to develope my own plugin. The idea it is to save the URL as hash string into database with the informations controller, action and parameter. But I have no idea which routing class I can extend… I think I must find the position into code where the URL is parse and before parsing my plugin checks if an entry of URL exists in database.

Have you any advice for me?



Is the idea to make it possible for a logged in user / admin to change how the urls should be displayed from the backend, similar to WordPress?

I think it’s a very special type of functionality that has to be tightly knit to a specific controller. I’m not sure if it’s even possible / meaningful to make a plugin for that…

But maybe I don’t really understand what exactly you want to achieve?

If you just want seo-friendly urls all you need is something like a slug field in your tables which you can use in place of the id.


Hi ali :slight_smile:

thank you for your answer!

For example I have a category like /categories/view/1 and this category slug should look like /home.

This I did not understand. Can you give an example, please?



Sure, let’s say you have a table called Categories with different entries which you want to be accessible via user friendly urls.

What you do is add a new field to your categories table called “slug” (or “alias” or “url” or whatever you like, it doesn’t matter). This field should contain the user friendly url for each entry, like “home” or “newest-articles” etc.

How you add the value to the slug field depends on your app. For example, you can take the title of the category and automatically convert it into a seo-friendly url (\Utility\Text::slug).

You can also do it manually through a form or maybe some other way.

In any case, the idea is that every entry has a unique slug, which you use in your links in place of id’s, i.e.:

$this->Html->link($category->title, ['controller' => 'categories', 'action' => 'view', $category->slug]) ?>

In your routes you connect it appropriately:

$routes->connect('/:slug', ['controller' => 'Categories', 'action' => 'view'], ['pass' => ['slug']]);

Then in your view action you should use the slug to find the entry in place of the id.

That’s a fairly easy way to do seo friendly urls.

If you’re concerned with performance (since slugs are a bit less efficient than ids), you could also use a combination of id and slug and then explode it and use the id, i.e.: /17-home

Hope this helps!


Thank you for the advice!


There are a few CakePHP plugins already that handle slug (SEO Friendly URLs). You can find most them here:✓&q=cakephp+slug