R
R
root092018-06-17 16:55:09
Laravel
root09, 2018-06-17 16:55:09

How to make cnc on laravel?

Now the pages go like this: /watch/1
You need to add a slug to the page address, i.e. something like this: /watch/1-slug
And there are a few questions:
Do I need to do (for SEO?) what would when going to /watch/1, it threw a 301 redirect to /watch/1-slug?
Do I need to do (for SEO?) so that when I visit /watch/1-random-string, it will throw a 301 redirect to /watch/1-slug?
What is the right way to do this in laravel itself?
Now I have done this:

Route::get('/watch/{id}-{slug}', '[email protected]');

public function get($id, $slug)
{
        $watch = Watch::findOrFail($id);
        if ($slug != $watch->slug)
            return redirect('/watch/'.$watch->id.'-'.$watch->slug, 301);
}

But there are two problems:
When accessing /watch/1, it throws a 404 error
When accessing /watch/1- it throws a 404 error
How to do it right?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yan-s, 2018-06-17
@root09

From an SEO point of view, the redirect is done so that there are no duplicates. If you don't use "/watch/1" and don't return a duplicate of the "/watch/1-slug" page, but 404, then everything is OK and nothing else is needed.
It's probably best to uniqueize the slug

A
Arman, 2018-06-17
@Arik

1. what prevents the entire line from being made as a slug and parsing or giving it to the model in the controller so that it decides what to do with such a slug?
2. yes, it's better to redirect to the desired URL, i.e. if you know id then ask model current url is equal or not

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question