Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

randm's avatar

Why do I always get a 404 error for any route I create?

Hi, I apologize for being a rookie. This is my first time using frameworks and I chose Laravel.

installed the composer and created my first project as per the docs http://laravel.com/docs/5.1/installation

when I go to https://sub.example.com/dev/public. As I should, I get this message "Laravel 5"

However, I added the following route to my routes.php file

Route::get('authors', array('as' => 'authors', 'uses' => 'Authors_Controller@getIndex')  );

Then created a new controller called Authors_Controller. and here is my controller code

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

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

class Authors_Controller extends Controller
{
    //

    public function getIndex(){

        return view('authors.index')->withName('Mike A');

    }
}

finally I created a new veiw called "index" (i.e. index.blade.php file) inside a folder called "authors" to look like this and here is my view's code hello {{ $name }}

However, I keep getting 404 error when I got to https://sub.example.com/dev/public/authors

What I could be doing wrong?

Yes, the mod_rewrite is enabled.

0 likes
10 replies
davorminchorov's avatar

Do you really need the subdomain called "sub" in the url? Maybe that's causing problems?

Just a quick tip on class naming: Don't use underscores for class names.

randm's avatar

@thepsion5 that gave me the results I need. "Hello Mike A"

What do I need to fix this problem?

thepsion5's avatar

@malhayek Check the section of the Laravel docs about enabling pretty URLs. Sometimes the default .htaccess file doesn't work depending on your server's configuration: http://laravel.com/docs/5.1/#installation

If the replacement .htaccess file doesn't work, it probably means that url rewriting is disabled or improperly configured on your apache server.

randm's avatar

@thepsion5 I change my .htaccess code from

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

to

Options +FollowSymLinks
RewriteEngine On

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

but that did not work.

When I execute this code on a separate page

if(in_array('mod_rewrite', apache_get_modules())){
    echo 'Enabled';
} else {
    echo 'Disabled';
}

I get "Enabled" for output.

When I enabled it I only removed the # signed from the line below "then restarted Apache"

LoadModule rewrite_module modules/mod_rewrite.so

Was there anything else that I would need to do?

roosevelt's avatar
Level 1

@malhayek,

Did you enable AllowOverride for your DocumentRoot? If you don't do that, then .htaccess has no effect on mod_rewrite.

Not sure what OS you are running but on a standard Ubuntu box the settings are something like below:

/etc/apache2/sites-available/yoursite.conf

<VirtualHost *:80>
    ServerAdmin youremail@yahoo.com
    ServerName yoursite.com
    ServerAlias www.yoursite.com
    DocumentRoot "/var/www/yoursite.com/public"
    <Directory /var/www/yoursite.com/public>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>
6 likes
randm's avatar

@roosevelt , thank you for your comment. My OS is windows 2008 r2

I don't have access to the server. But if needed I can share my apache config file in the morning.

FalguniM's avatar

I had same problem and I solved it by the solution given by @roosevelt. AllowOverride All was required to add in apache conf.

Please or to participate in this conversation.