Search code examples
laravellaravel-8laravel-routing

Laravel 8: Seo Friendly Instagram like Username URL system


I recently worked on usernames for one project and wanted to make a system with usernames right next to domain name just like for example Instagram.com/{username}, Facebook.com/{username} or even Twitter.com/{username}.

My Route:

Route::get('{username}', [HomeController::class, 'index'])->name('dashboard');

Which works absolutely fine. But I am not able to understand how will SEO detect such dynamic URLs like we can see Facebook and Instagram usernames are at times shown on google and also bing. Is this the right method to do so? Or am I going wrong with this? Someone recently suggested for such URL 301 is supposed to be done, & now I'm quite confused about how in such cases can we do 301 for such URLs?


Solution

  • What you're doing is fine but I don't understand the part about 301 redirections.

    Your concern about crawl engines not discovering unexposed URL's is valid. In fact, it's very unlikely Google Bot will crawl yourwebsite.tld/{username} unless you have an external link pointing to it.

    To remedy the issue you have two options:

    • Have links on indexed pages pointing to new pages you want bots to discover (organic indexing).

    • Or, the proper solution, create a sitemap at the root of your website to help search engines discover your website pages.

    With Laravel there's many different ways to create a sitemap.xml. Since your User model is dynamic, you will want your sitemap to be dynamic as well. You can build this feature yourself or you can download an existing package to save time. I personally like spatie/laravel-sitemap but any similar package would do the job.