1
votes

I'm new to Laravel. I have the following route:

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::get('about', 'PagesController@about');

And here is my controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class PagesController extends Controller
{
    public function about()
    {
        return 'about';
    }   
}

When I navigate to: http://localhost/laravelnew/public/about/ I get a 404 Not found. I can't understand Why.

My .htaccess-file in public-folder:

<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>
1
Try to do this in your browser localhost/laravelnew/about you should not have the /public/ in you urlFranco
@Franco: That don't work. I just get The requested URL /laravelnew/public/about/ was not found on this server.Bryan
if you go to localhost/laravelnew/public you see the laravel welcome screen?Amir Bar
What I mean is that /public/ should't be in your url are you using the original '.htaccess'?Franco
@amirbar: No, because I have removed that Route. I am following this guide: laracasts.com/series/laravel-5-fundamentals/episodes/4 When I change my route to ('/', 'PagesController@about''), it works.Bryan

1 Answers

0
votes

I see you're working locally, so you should enable mod_rewrite for it to work.

Cheers!

EDIT:

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

    RewriteEngine On
    RewriteBase /

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>