My Routes are Returning a 404, How can I Fix Them?

前端 未结 18 840
栀梦
栀梦 2020-12-23 10:44

I\'ve just started learning the Laravel framework and I\'m having an issue with routing.

The only route that\'s working is the default home route that\'s attached to

相关标签:
18条回答
  • 2020-12-23 11:36

    Have you tried adding this to your routes file instead Route::get('user', "user@index")?

    The piece of text before the @, user in this case, will direct the page to the user controller and the piece of text after the @, index, will direct the script to the user function public function get_index().

    I see you're using $restful, in which case you could set your Route to Route::any('user', 'user@index'). This will handle both POST and GET, instead of writing them both out separately.

    0 讨论(0)
  • 2020-12-23 11:37

    Try enabling short php tags in your php.ini. WAMP has them off usually and laravel needs them on.

    0 讨论(0)
  • 2020-12-23 11:38

    You could try to move root/public/.htaccess to root/.htaccess and it should work

    0 讨论(0)
  • 2020-12-23 11:38

    OK, so after bashing my head on this problem for a little over a day... I got up and did what I SHOULD have done yesterday, and DEBUGGED what was going on!

    What Laravel is TRYING to do here, is insert the file index.php right in front of the path given as a Route. SO for instance, if you specified a Route::get('/account/create', ..., and execute your app from say localhost/laravel/authenticate/public/account/create on your browser, then laravel wants to execute localhost/authenticate/public/index.php/account/create, but to do that.... Apache needs to see that requests through /wamp/www/laravel/laravel/authentication/public (your path may vary somewhat, depending on where your laravel app is actually installed, but the trailing public is where the substitution needs to take place) must have a 'RewriteRule' applied.

    Thankfully, laravel supplies the correct Rewrite rule in a handy .htaccess file right there in your app's public folder. The PROBLEM is, the code in that '.htaccess' file won't work with the way WAMP is configured out of the box. The reason for this SEEMS to be the problem suggested by muvera at the top of this thread -- the rewrite_module code needs to be loaded by Apache before the RewriteRule stuff will work. Heck this makes sense.

    The part that DOESN'T make sense: simply stopping and restarting Apache services will not pick up the changes necessary for WAMP to do the right thing with your RewriteRule -- I know, I tried this many times!

    What DOES work: make the changes suggested by muvera (see top of thread) to load the correct modules. Then, reset your whole Windows session, thus dumping Apache out of memory altogether. Restart (reload) WAMP, and VOILA! the fix works, the correct RewriteRule is applied, yada, yada; I'm living happily ever after.

    The good news out of all this: I know a LOT more about .htaccess, RewriteRule, and httpd.conf files now. There is a good (performance) argument for moving the logic from your app's public .htaccess file, and putting it into a Directory ... section of your httpd.conf in your Apache 'bin' folder BTW (especially if you have access to that folder).

    0 讨论(0)
  • 2020-12-23 11:39

    If you're using Vagrant though Homestead, it's possible there was an error mounting the shared folder. It looks like Vagrant takes your files from that folder and swaps out the files that are actually on the host machine on boot, so if there was an error, you're essentially trying to access your Laravel installation from when you first made it (which is why you're only getting "home"- that was generated during installation).

    You can easily check this by sshing into your vm and checking the routes/web.php file to see if it's actually your file. If it isn't, exit out and vagrant halt, vagrant up, and look for errors on boot.

    0 讨论(0)
  • 2020-12-23 11:40

    Have you tried to check if

    http://localhost/mysite/public/index.php/user 
    

    was working? If so then make sure all your path's folders don't have any uppercase letters. I had the same situation and converting letters to lower case helped.

    0 讨论(0)
提交回复
热议问题