waltun's avatar

How to fix duplicate links problem in Laravel

I have a URL for my categories like this : example.com/shop/category1 And this is code in my web.php :

Route::any('shop/{slug}', 'CategoryController@category')->name('category');

And I have many other routes for products, articles Etc. But when I analyze my website, I have this shop in all routes like this :

example.com/products/shop

example.com/articles/shop

example.com/shop/shop

Other routes works fine, I don't know what is the problem ! Oher routes :


Route::get('products/{slug}', 'ProductController@detail')->name('products.detail');

Route::get('articles', 'ArticleController@index');

Route::get('articles/{slug}', 'ArticleController@detail')->name('articles.show');
0 likes
7 replies
sr57's avatar

HI @waltun

First, put your code between 3 ` to make it clear

like this

Second, what do you mean by 'when I analyze my website' ? Show your routes (php artisan routes:list)

1 like
waltun's avatar

In route list I don't have this shop route like example.com/product/shop But when I analyze website links for SEO I have this /shop in all routes.

sr57's avatar

SEO can only see what you have in your html pages, so look at the sources of them versus your Laravel code.

waltun's avatar

You mean it's not from Laravel codes ?

sr57's avatar

No, I mean :

  • if you don't find 'false link' in your html code, it can be a pb of cache (somewhere)

  • if you find a 'false link' in your html, share it here with your web.php

waltun's avatar

This is other routes in web.php :

Route::get('/articles', 'ArticleController@index');

Route::get('/articles/{aslug}', 'ArticleController@detail')->name('articles.show');

Route::any('/products', 'ProductController@index')->name('products.index');

Route::get('/products/{pslug}', 'ProductController@detail')->name('products.detail');

Route for /shop :

Route::any('/shop/{cslug}', 'CategoryController@category')->name('category');

And when I run php artisan route:list I don't have problem in list

Please or to participate in this conversation.