divHelper11
divHelper11

Reputation: 2208

Laravel routes do not work at all

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>

Upvotes: 1

Views: 487

Answers (2)

Mina Abadir
Mina Abadir

Reputation: 2981

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/;

Upvotes: 2

user991
user991

Reputation: 1369

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/

Upvotes: 1

Related Questions