Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

2bezzat's avatar

routes doesn't work unless i use artisan serve

Hello guys,

I've finished a project and I'm in deployment state but I'm facing a WEIRD problem , on my laptop I normally use php artisan serve to test my website and all things work just fine and smooth , however when I published it on my hosting -shared- and visit website/public/courses ... wel I get a 404 Not Found page ... I thought it was from my server but when I tried not to use php artisan serve in my laptop and visit localhost/projectName/public/courses I get the same exact page !

I use php artisan serve and visit the same page and it works ! what is the problem form !

here is my routes

Route::get('/','HomeController@index'); Route::get('/home', 'HomeController@index'); Route::get('courses','HomeController@courses'); Route::get('course/{id}','HomeController@course'); Route::get('events','HomeController@events'); Route::resource('subscribe','BeneficiaryController'); Route::group(['prefix' => 'admin', 'middleware' => 'auth'], function() { Route::get('/', function () { return view('admin.index'); }); Route::resource('/courses', 'admin\CoursesController'); Route::delete('/courses/{id}/delete', 'admin\CoursesController@destroy'); Route::resource('/events', 'eventsController'); Route::delete('/events/{id}/delete', 'eventsController@destroy'); Route::get('/subscribtions','AdminController@users'); Route::get('/subscribtions/course/{id}','AdminController@courseUsers'); Route::get('/subscribtions/event/{id}','AdminController@eventUsers'); });

not ,I'm using linux with Apache 2 server

0 likes
10 replies
SaeedPrez's avatar

On your hosting it should be website.com/courses if installed correctly. Otherwise search for shared hosting on Laracasts or on Google, there must be at least 1 000 000 posts on this subject.

2bezzat's avatar

@SaeedPrez It's not about moving the public from the URL , It's about that the routes doesn't work unless I use php artisan serve . courses is a get route from many other routes that doesn't work and it isn't working even on my localhost

simondavies's avatar

if your routes then post an example for them for others to view and inspect to.

Snapey's avatar

Dont be so quick to dismiss expertise

Remove /ProjectName/public/ from your routes and you will be ok. Why? How about

Route::get('/home', 'HomeController@index'); 

so, the router is expecting the home page to be /home but on your hosting, you are somehow hoping that /ProjectName/public/home will resolve to the same place.

Sort out the path correctly.

2bezzat's avatar

@Snapey sorry man but my poor English didn't help me to understand exactly what do you mean .However, I've fixed the problem by just adding index .php so the path on my laptop became localhost/ProjectName/public/index.php/course or any other routes and it worked fine ...The problem was with Cache as I've tried this approach before and didn't work and on cleaning the cache it worked :'D

1 like
michaelmcmullen's avatar

If you have to add index.php take a look at your server and see if modrewrite is turned on

2 likes
SmoDav's avatar

As @michaelmcmullen has said above, the problem might just be that mod rewrite is not enabled. Secondly, check your apache.conf and verify that AllowOverride for the document root is set to All so that the .htaccess can be used to do the rewriting

3 likes
2bezzat's avatar

@michaelmcmullen @SmoDav Thanks Guys , I had mod rewrite enabled but I didn't AllowOverride but I did now :D but I'm still facing the same problem ...Can any one give me A working .htacess file please ?! and where to place it ?!

Snapey's avatar

Ordinarily you would put it in public, which should be your root folder... oh, no, wait, you already dismissed that as a concept.

1 like

Please or to participate in this conversation.