Rafael Adel
Rafael Adel

Reputation: 7759

New to Laravel PHP framework. Routes other than "/" doesn't work

I'm a beginner at Lavarel framework. I know about MVC structure, Since I've used it before inside ASP.net, But using Laravel is quite confusing to me.

I've installed Laravel inside photozoom directory using:

composer create-project laravel/laravel photozoom --prefer-dist

Here's my app/routes.php :

<?php

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

Route::get('users', function()
{
    return 'users route is working!';
});

When i run http://localhost/photozoom/public/users, I get 404 Not Found error.

But when i try http://localhost/photozoom/public/, The route for / is invoked and the corresponding view is called.

I even tried to create a view for the users route. Using Laravel documentation. I've created two files :

layout.blade.php :

<html>
    <head>
        <title>Laravel Quickstart</title>
    </head>
    <body>
        <h1>Laravel Quickstart</h1>

        @yield('content')
    </body>
</html>

users.blade.php :

@extends('layout')

@section('content')
    Users!!!
@stop

But still, When i call http://localhost/photozoom/public/users I get 404 Not Found error.

Here's my public/.htaccess file:

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On

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

I'm using PHP 5.5, Apache 2.4.6 .

Any help would be appreciated.


SOLVED After enabling mod_rewrite, I had to enable AllowOverride too.

Upvotes: 15

Views: 16908

Answers (4)

Dilip Suthar
Dilip Suthar

Reputation: 65

if you're running windows 10 then you just need to do one thing simple as enough.

create new folder in c:/wamp64/www/ and copy your all file from laravel folder and paste in folder which you just created thats my solution.

Upvotes: 0

Z00tj3
Z00tj3

Reputation: 81

The .htaccess file in the /public directory enables pretty URLs. In order for the .htaccess file to do its work:

  • Apache2 must have mod_rewrite enabled (a2enmod rewrite)
  • In your Apache configuration you must use the AllowOverride option to allow the .htaccess file to 'override' your default Apache2 configuration.

For example:

<Directory /var/www/photozoom/> 
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Upvotes: 7

Lahiru Abeyrathna
Lahiru Abeyrathna

Reputation: 1

There are two AllowOverride in the httpd.conf file.

<Directory />
    AllowOverride All
    Require all denied
</Directory>

and

DocumentRoot "D:/www"
<Directory "D:/www">
    AllowOverride All
    Require all granted
</Directory>

Upvotes: 0

Franz
Franz

Reputation: 11553

Try http://localhost/photozoom/public/index.php/users for now. And then enable pretty URLs.

Upvotes: 24

Related Questions