Laravel 4 all routes except home result in 404 error

Just try laravel 4, which I installed using composer. Installed a virtual host. Only the root route works:

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

Even that doesn't work

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

What I'm trying to push is the TasksController in /tasks :

 Route::resource('tasks', 'TasksController'); 

That gives me 404 too.

What can i do wrong? I followed these instructions during installation: http://chris-schmitz.com/getting-started-with-laravel-4/

I also have a default .htaccess file in the root of my project:

 <IfModule mod_rewrite.c> Options -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule> 

I am using mac using localhost.

+46
laravel routing
Nov 22
source share
17 answers

Just for fun, see if /index.php/hello works.

If so, then this is most likely a .htaccess problem.

+93
Nov 22
source share

Was there the same problem as Laravel 4 on WAMP (Windows 8).
The solution that worked for me was:

  • Open apache httpd.conf and find the following line:

     #LoadModule rewrite_module modules/mod_rewrite.so 
  • Uncomment this line (remove # )
  • Save httpd.conf
  • Restart WAMP

It should work!

+36
May 31 '13 at 19:04
source share

I had the same problem and the solution enabled the rewrite mode on Apache2

In the terminal, use the following commands:

 $ sudo a2enmod rewrite $ sudo service apache2 restart 

And the magic!

+25
Oct 22 '14 at 12:35
source share

Had the exact same problem.

Two things I needed to do to fix this:

  • enable rewrite_module in Apache
  • Change the AllowOverride from None to All , e.g. (Apache 2.4.9):

    FollowSymLinks MultiViews Index Parameters AllowOverride All Require All Provided

FYI: use Laravel Homestead with VirtualBox and Vagrant instead of WAMP. It contains Nginx instead of Apache, but everything works by default, as it is explicitly configured for Laravel.

+13
Jan 17 '15 at 11:22
source share

You do not need to / when defining anything other than home:

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

Must work.

+6
Nov 22 '12 at 14:45
source share

Even after you enable mod_rewrite, you may run into this problem if you have aliased your larvel / public folder.

Adding

 RewriteBase /your_apache_alias 

to.htaccess does the trick.

+6
Sep 14 '13 at 2:01
source share

Since Laravel 4 is an autoload of files from the card in a static file, you need to update this file when adding a new controller. Run this command to restore the static file:

 php composer.phar dump-autoload 
+4
Nov 24
source share

I had this problem (on Windows with manually installed Apache 2.2) and the reason was the lack of AllowOverride in my VirtualHost, since the root directory in httpd.conf was None by default.

FileInfo Options=MultiViews - the minimum set required for Laravel.htaccess

eg.

 <VirtualHost *:80> DocumentRoot "C:/htdocs/domain.com/laravel/public" ServerName foo.domain.com <Directory "C:/htdocs/domain.com/laravel/public"> AllowOverride FileInfo Options=MultiViews </Directory> </VirtualHost> 

Or use AllowOverride All if this does not work and you do not care about security.

+3
Aug 2 '14 at 6:57
source share

It’s pretty clear that the problem is due to "mod_rewrite", in some cases it is enough to include this module in Apache to fix it.

However, in my case, I had to expand the configuration for VirtualHost as follows:

 <VirtualHost *:80> ServerName adplus.local ServerAdmin sergey.donchenko@gmail.com DocumentRoot /var/www/adplus.local/project/public **<Directory "/var/www/adplus.local/project/public"> AllowOverride All </Directory>** ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> 
+3
Jan 28 '15 at 7:15
source share

I tried all this without success, then I found another post and changed my .htaccess to this:

 <IfModule mod_rewrite.c> Options -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ /index.php [L] </IfModule> 
+3
Mar 08 '15 at 6:32
source share

This is similar to @GaryJ and @MartinGomez. This is the .htaccess content that should be installed in the public folder for all your laravel 4 projects running on the Apache server:

 <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> 
+2
Nov 13 '14 at 12:49
source share

The previous answer had a slight flaw. This can help.

 $ sudo a2enmod rewrite $ sudo service apache2 restart 

I hope he does it.

+2
Jan 15 '15 at 2:02
source share

Switch to

nano / etc / nginx / sites-available / yoursite

find the try_ file and replace as shown below:

try_files $uri $uri/ /index.php?$query_string;

+2
Dec 23 '16 at 15:04
source share

For Nginx users, you probably copied the default virtual host, but Laravel requires some configuration in the location directive to allow the Laravel application to perform routing rather than Nginx.

In /etc/nginx/sites-available/your-site-name replace the location directive with the following:

 location / { try_files $uri $uri/ /index.php$is_args$args; } 

Then run sudo service nginx reload for the changes to take effect.

+1
Dec 21 '16 at 13:38
source share

This update worked for me. In the .htaccess file, simply add the following after enabling Rewriterules.

 Options -Indexes Options +FollowSymLinks 

It works like a charm

0
Jan 15 '15 at 2:08
source share

This comment may be a bit late, but it may help. I had the same problem when routing to a different view:

 Route::get('index', function () { return view('index'); }); Route::get('login', function () { return view('login'); }); 

But it didn’t work, so I tried everything I found in all the related messages, but this was not enough to solve my problem, so I found these lines on httpd.conf:

 <Files ".ht*"> Require all denied </Files> 

So, I changed "denied" to "provided", and also commented on this line on my .htaccess:

 #RewriteBase / 

And working! I think that these lines cause Apache not to consider your project's .htaccess file, so turning it into a provided one made a difference. Hope this helps someone with the same issue.

Work with Apache Server 2 @Manjaro Linux (based on Archlinux)

0
Sep 13 '16 at 22:45
source share

I had a similar problem on Ubuntu 14.04 with Lumen 5.4.

The solution was two parts for me. First, in my vhost /etc/apache2/sites-enabled/my_vhost.conf file, I had to add the following <Directory> entry to allow overrides after declaring my DocumentRoot :

  DocumentRoot /var/www/path/to/my/app/public <Directory "/var/www/path/to/my/app/public"> Options FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> 

Then I had to enable rewriting with

 sudo a2enmod rewrite sudo service apache2 restart 
0
Aug 27 '17 at 2:51 on
source share



All Articles