Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel redirects to a route but then apache gives 404 error

I have a site that is working on the same server in a different url (staging), but now I've deployed the site and the base url ("/") is redirected to the login url (so laravel is sort of working), but then I get a 404 error from apache.

If I use sub.domain.com/index.php/route, it works, but if I use sub.domain.com/route redirects to the login route and gives a 404 error.

I also changed the routes.php to return the login view in the route "/" and it show the login form correctly.

like image 543
Proença Avatar asked Mar 31 '14 09:03

Proença


People also ask

How do I fix error 404 in laravel?

It should be enough to just run php artisan vendor:publish --tag=laravel-errors and then edit the newly created resources/views/errors/404.

How do I change the default 404 in laravel?

You need to create blade views for error pages, move to this path resources/views/ inside here create errors folder and within the directory create 404. blade. php file. It will redirect you to the 404 page if you don't find the associated URL.


3 Answers

After adding

AllowOverride All

to the vhost configuration, got it working. Probably the default configuration wasn't allowing the redirects?

Here's my final (and working) vhost configuration:

DocumentRoot /var/www/sitefolder/public
 ServerName site.domain.com
 <Directory /var/www/sitefolder/public>
  AllowOverride All
  allow from all
  Options +Indexes
</Directory>
like image 62
Proença Avatar answered Oct 21 '22 04:10

Proença


For VirtualHost

Only add these lines into httpd.conf of your apache:

<Directory /var/www/sitefolder/public>
  AllowOverride All
  allow from all
  Options +Indexes
</Directory>

Or you can replace the first line with:

<Directory />

And if all doesn't work, you can try:

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
like image 28
ch271828n Avatar answered Oct 21 '22 04:10

ch271828n


The problem might come from a module in your Apache server called rewrite module. in windows you can just uncomment this line from your httpd.conf

#LoadModule rewrite_module modules/mod_rewrite.so

I'm running Ubuntu 14.04 and enabled it using

sudo a2enmod rewrite

Try these with an Apache restart. It might work for you as well.

like image 29
Mehrdad Hedayati Avatar answered Oct 21 '22 03:10

Mehrdad Hedayati