3

I am starting to learn how to work with laravel but got a problem. When I go to: http://localhost/testing/public/ I get a working page but when I typ for example http://localhost/testing/public/home which is one of my views I get a 404 error. Does someone know how to fix this?

Edit: I am using the latest version of laravel and when I do for example:

Route::view('/home', 'home');

In my routes/web.php I get that error

MrAndre
  • 811
  • 1
  • 10
  • 26
  • One way would be to set up a domain the points to the public folder of your app https://laravel.com/docs/5.5/installation#configuration. https://stackoverflow.com/questions/16229126/using-domain-name-instead-of-localhost-in-with-https-in-xampp – Rwd Sep 08 '17 at 10:12
  • @MrAndre check the edited answer – Sletheren Sep 08 '17 at 11:31

4 Answers4

3

This is more likely a problem with virtual Hosts, try the following:

  • First edit your route to :Route::get('/home', function(){echo "hello"});
  • Then try to access: http://localhost/testing/public/index.php/home

If it works then its certainly because you don't have a virtualHost, you can set it easily in your Xampp config and modifying ur hosts file

  • First go to C:\Windows\System32\drivers\etc\hosts and add a new line like: 127.0.0.1 yoursite.local
  • Then go to where xampp is installed under xampp\apache\conf\extra\httpd-vhosts.conf
  • Then add a virtual host in the bottom of the file like:

<VirtualHost *:80>

DocumentRoot "PATH_to_laravel_folder/public"  

ServerName yoursite.local  

</VirtualHost>

  • Then you can access your route by typing: yoursite.local/home or yoursite.local:80/home

Hope it helps you guys :)

Sletheren
  • 2,435
  • 11
  • 25
  • 2
    That does work for me do you maybe have a tutorial or something how you could fix this for xampp? – MrAndre Sep 08 '17 at 11:24
  • Thanks works fine:) One last question when you have for example project.local/home it redirects you go google because he thinks it is invalide so you have to put http:// before it now is here a workaround for? – MrAndre Sep 08 '17 at 11:57
  • well you have to put the protocol which is http:// so the browser knows that this is an url and not something you're searching for :) – Sletheren Sep 08 '17 at 12:02
0

It may be because of routes. after creating a view you have to add it in routes/web.php

like Route::view('/yourUrl', 'viewName'); in 5.5 version. for 5.4 or older versions Route::get('/yourUrl', 'viewName');

after adding this to routes/web.php. you can access http://localhost/testing/public/yourUrl

you can find more here

Mahmood Sanjrani
  • 108
  • 3
  • 19
0

If http://localhost/testing/public/index.php/home works, try to create a .htaccess file in public directory with:

RewriteEngine On
RewriteBase /testing/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
-1

Run $ composer install in you command line

Mario Perez
  • 2,777
  • 1
  • 12
  • 21
  • Please don't post "try this" answers. Either answer with confidence or otherwise post it as a comment (when you have enough points). – Gert Arnold Jan 01 '23 at 18:45