1

My laravel routes are not working at all. I tried something like this:

Route::get('welcome', function () {
    return View::make('welcome');
});

Accessing it with localhost/project/project/public/welcome works fine. I have tried it in many ways but seems like routes aren't working since localhost/project/welcome show me 404 error. I know there is simillar topic but there is no answer for me. Could somebody help me out please?

My htaccess file looks like this (I have never touched it):

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
divHelper11
  • 2,090
  • 3
  • 22
  • 37

2 Answers2

2

You need to edit your HTTP server to have the document root as project/project/public/

For example in Apache you can do something like that:

<VirtualHost *:80>                                                                                                                                                                                                                                                     
        ServerAdmin webmaster@localhost                                                                                                            
        DocumentRoot /var/www/project/project/public/

And in Nginx it will like that:

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/project/project/public/;
Mina Abadir
  • 2,951
  • 2
  • 15
  • 20
1

You have said that you can access your laravel app throught
localhost/project/project/public/welcome. This is because this path is your starting root path, from where you start your application.

Example that will allow you to access new route

Route::get('other_route', function () {
    return View::make('welcome');;
});

This code can be accessed, if you will type localhost/project/project/public/other_route into your browser

localhost/project/welcome won't work because your application is deeper than this path.

You should setup virutal host for your application so that your path could be myapp.local/welcome myapp.local/other_route

Or access your application, assuming that your start point is http://localhost/project/project/public/

user991
  • 1,339
  • 2
  • 24
  • 45
  • I thought that in laravel everything in url after slash `/` is in the public folder. Thats what i need actually. To make the public folder my starting point in url – divHelper11 Nov 22 '15 at 21:15
  • If i understood your question right, it is your web server misconfiguration, not laravel issue – user991 Nov 22 '15 at 21:17
  • Oh I was sure that i need to config it from the inside of laravel project. There are server settings etc – divHelper11 Nov 22 '15 at 21:19
  • you can start laravel's php web server, typing command `php artisan serve` in your OS console from your application root, and you will be able to run your project from http://localhost:8000/ – user991 Nov 22 '15 at 21:19