Reputation: 3200
I just started learning laravel 4 but I am having issues with the routes. When I go to my root url the routes seem to be working fine but when I try accessing my second route I get a 404 error and the server logs show a 'file not found' error.
I set AllowOverride ALL and changed the original .htaccess code to the one I posted below.
Note: example.com is working and it returns All cats
as it supposed to.
This is the code:
Routes
Route::get('/', function(){
return "All cats";
});
Route::get('cats/{id}',function($id){
return "Cat #$id";
})->where('id','[0-9]+');
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
httpd.conf
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/cats/public
ServerName example.com
ErrorLog logs/example.com-error_log
CustomLog logs/example.com-access_log common
</VirtualHost>
HTML error when trying to access example.com/cats/123
The requested URL /cats/123 was not found on this server.
Error log
File does not exist: /var/www/html/cats/public/cats
Upvotes: 0
Views: 389
Reputation:
The AllowOverride
directive is per-directory, thus putting it randomly in Apache's configuration file won't work.
Create a new Directory
block for the public
directory in your Laravel installation, and put the AllowOverride All
in there, like so :
<Directory "/path/to/your/laravel/public">
AllowOverride All
</Directory>
Also if you're only hosting a single Laravel installation there is no need to use a virtual host like you did, just change the existing DocumentRoot
directive and Directory
block to both point to your Laravel's public directory, and add the AllowOverride All
in that directory block.
Upvotes: 4