How can I fix Laravel 5.1 - 404 Not Found?

I am trying to use Laravel 5.1 for the first time. I was able to install it, and https://sub.example.com/laravel/public/ shows what should. However, the views I create give me a 404 error page that was not found.

Here is what I have done so far:

I created a controller in laravel\app\Http\controllers\Authors.php

Here is the code for the Authors.php file

 <?php class Authors_Controller extends Base_Controller { public $restful = true; public function get_index() { return View::make('authors.index') ->with('title', 'Authors and Books') ->with('authors', Author::order_by('name')->get()); } } 

Then I created the view in laravel\resources\views\Authors\index.blade.php

Here is the code for index.blade.php

 @layout('layouts.default') @section('content') Hello, this is a test @endsection 

Then I created the layout in laravel\resources\views\layouts\default.blade.php

Here is the default.blade.php file code

 <!DOCTYPE html> <html> <head> <title>{{ $title }}</title> </head> <body> @if(Session::has('message')) <p style="color: green;">{{ Session::get('message') }}</p> @endif @yield('content') Hello - My first test </body> </html> 

Finally I created a route in laravel\app\Http\routes.php

 <?php Route::get('/', function () { return view('welcome'); }); Route::get('authors', array('as'=>'authors', 'uses'=>' authors@index ')); 

But for some reason I get an error 404 Page not found.

I enabled mod_rewrite on my Apache 2.4.9, uncommenting the line

 LoadModule rewrite_module modules/mod_rewrite.so 

Then restarted Apache.

From what I can say in the output of php_info() , mod_rewrite is enabled

 Loaded Modules core mod_win32 mpm_winnt http_core mod_so mod_php5 mod_access_compat mod_actions mod_alias mod_allowmethods mod_asis mod_auth_basic mod_authn_core mod_authn_file mod_authz_core mod_authz_groupfile mod_authz_host mod_authz_user mod_autoindex mod_cgi mod_dir mod_env mod_include mod_isapi mod_log_config mod_mime mod_negotiation mod_rewrite mod_setenvif mod_socache_shmcb mod_ssl 

My current .htaccess file looks like this: "This is the factory default setting"

Options -MultiViews

 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] 

I also tried changing it to the code below as per the documentation :

 Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] 

However, I still get page 404 when I go to

 https://sub.example.com/laravel/public/authors 

What am I doing wrong? How can I solve this problem?

+8
source share
7 answers

I see the same behavior as the visit / route opportunity, but all other pages return 404 when I first install Laravel sites.

In your apache configuration file httpd.conf or httpd-vhosts.conf you need to include directives that can be placed in the .htaccess file.

Here is an example of my VirtualHost configuration:

 <VirtualHost *:80> ServerAdmin admin@gmail.com DocumentRoot "C:/www/laravel_authority-controller_app/public" ServerName authoritycontroller.www ErrorLog "logs/AuthorityController.www-error.log" CustomLog "logs/AuthorityController.www-access.log" common <Directory "C:/www/laravel_authority-controller_app/public"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks Includes ExecCGI # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # AllowOverride FileInfo AuthConfig Limit # AllowOverride All # # Controls who can get stuff from this server. # Require all granted </Directory> </VirtualHost> 

The key to your problem is AllowOverride All . This should be enough to make the site work, but you can also enable options and Require all granted if they are consistent across the entire website.

+16
source

if you are on ubuntu you do 3 things. 1. Verify that "/var/www/html/YourProject/public/.htacess" is as follows.

 <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] # Handle Authorization Header RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 

2. Add these lines to / etc / apache 2 / sites-available / 000-default.conf

 <Directory "/var/www/html"> AllowOverride all Require all granted </Directory> 

Note: remember that this is a system file, so you should use this comamd

 sudo gedit /etc/apache2/sites-available/000-default.conf 
  1. last rewrite module.

    LoadModule rewrite_module modules / mod_rewrite.so

or

 sudo a2enmod rewrite 
+6
source

If your Laravel routes do not work and you get "Not Found" errors when you try to load the page, your .htaccess file most likely does not have the right to perform its duties.

The key is the apache AllowOverride directive.

If you do not have AllowOverride for All, your Laravel.htaccess file ( /public/.htaccess ) will not be able to include mod_rewrite, and your routes will not work.

The first step is to open the apache httpd.conf file. In OS X, it is located at:

 /private/etc/apache2/httpd.conf 

Option 1) Change your main directive

This will change the AllowOverride value for all of your websites. In the httpd.conf file, find the main directive:

 **<Directory "/var/www/html"> ... AllowOverride None ... </Directory>** 

Just change it to this:

 **<Directory "/var/www/html"> ... AllowOverride All ... </Directory>** 

Option 2) Add a directive to the directive of your site.

 ** <VirtualHost 127.0.0.1:80> DocumentRoot "/var/www/html/epigroove/public" ... <Directory "/var/www/html/epigroove/public"> AllowOverride All </Directory> </VirtualHost> 

**

Save the changes to the httpd.conf file, restart or reload apache and your routes should be up and running.

+2
source

If you are using Apache HTTPD 2.2.15 on Linux (CentOS 6.7 in my case), the directory directive will look like this:

 <Directory /> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All allow from all </Directory> 

You probably don't need a parameter string unless you use these parameters.

Thanks, answer 2.4. This helped me solve this problem for me on 2.2, and I have another server with 2.4, I can apply it too.

+1
source

also URL case sensitive to folder name

folder name: camelCase then the url should be localhost/camelCase/route-1

hope this helps someone xD is a little silly

0
source

If it's on a live server, try this, it worked for me.

 <IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews -Indexes </IfModule> Options +FollowSymLinks RewriteEngine On RewriteBase / # Handle Authorization Header RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} (.+)/$ RewriteRule ^ %1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] 

0
source

you must first save your project by pressing control + s on the keyboard and test again. The problem will be fixed.

0
source

All Articles