Usually the "drill down" query url strings doesn't need any level of SEO. User is on site already. Even on laracasts there are regular query strings:
?page=1&replyId=760390
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I want to build SEO friendly URLs for ecommerce website and until now I was using https://github.com/spatie/laravel-sluggable but I want to take it even further.
I want to have this structure:
One way it will be to have something like:
/**
* First we check if it is category
*/
Route::get('{categories}', function ($categories) {
$categories = explode('/', $categories);
$current_category_slug = array_pop($categories);
if($current_category = Category::where("slug",$current_category_slug)->first()) {
return 'category view';
}
})->where('categories', '^[a-zA-Z0-9-_\/]+$');
/**
* Else if it is a product
*/
Route::get('{categories}', function ($categories) {
$categories = explode('/', $categories);
$current_product_slug = array_pop($categories);
if($current_category = Pruduct::where("slug",$current_product_slug)->first()) {
return 'product view';
}
})->where('categories', '^[a-zA-Z0-9-_\/]+$');
I think a better way will be to store all the possible urls in the database and cache them with redis. Also in the database I will store the controller and action I found one old package - https://github.com/dmcdenissen/urlalias
Does anyone have better suggestion or maintained package?
Please or to participate in this conversation.