salesn's avatar
Level 1

The problem is changing the URL route name

Hello everyone and happy New Year!

The problem is changing the URL (laravel)

In the file web.php

Route change

Route::get('service', [ServiceControllerForFront::class,'index'])->name('front.services'); Route::get('service/{slug}', [ServiceControllerForFront::class,'detail']);

I regret that service/ is service/ ... but as soon as I change the route it shows a 404 error. Where am I wrong?

0 likes
9 replies
Sinnbeck's avatar

You change what to what? And what url gives 404?

salesn's avatar
Level 1

mysite.com/servis is ok mysite.com/service/ --> mysite.com/servis/

I want it to be instead of /service ---> /servis/:

Original:

Route::get('servis', [ServiceControllerForFront::class,'index'])->name('front.services'); Route::get('service/{slug}', [ServiceControllerForFront::class,'detail']);

It should be:

Route::get('servis', [ServiceControllerForFront::class,'index'])->name('front.services'); Route::get('servis/{slug}', [ServiceControllerForFront::class,'detail']);

The error is shown by the page generated under Route::get('servis/{slug}' and with Route::get('service/{slug}) everything is fine.

salesn's avatar
Level 1

Hmm ... Could not open file: artisan. I can't clear the cache.

It is interesting that if I manually change the URL instead of service --> service then it works normally

mysite.com/service/example ---> 404 error mysite.com/servis/example ---> OK url (manually entered /servis/)

:(

tykus's avatar

@salesn a couple of points/queries because the issue is not clearly stated:

Hmm ... Could not open file: artisan. I can't clear the cache.

You must execute any Artisan commands from the project's root directory; where an artisan file should exist.

manually change the URL instead of service --> service then it works normally

What is changed here?

The error is shown by the page generated under Route::get('servis/{slug}' and with Route::get('service/{slug}) everything is fine.

Because the registered URL is /service/{slug}, not /servis/{slug}?

Why don't you list your Routes and see what is actually registered?

php artisan route:list

NOTE: This might still be an issue of Route caching, since you didn't successfully execute that command!

salesn's avatar
Level 1

I started the site on Linux Ubuntu 22 / Apache ... and I didn't install Laravel tools because I didn't know how.

The script (Villa CMS) installed successfully and works nicely.

The site is working but it is very complicated about URL changes. Does everything have to be like that? Also sitemap.xml can't be loaded and shows 404 error. Thank you for your help.

tykus's avatar

@salesn if it is a Laravel application, then it likely has "Laravel tools" baked in... It seems like you might need professional help?

salesn's avatar
Level 1

I agree. It doesn't have to be a hair transplant...

tykus's avatar

Difficult to say what the problem might be if that’s the analogy?

Please or to participate in this conversation.