Why do my laravel routes not work?

Posted May 28, 2016 123.5k views
ApachePHPLAMP StackDigitalOcean

Hi, i just deployed my laravel project to digital ocean. The mysql database is correctly migrated and seeded (checked in phpmyadmin). I can currently surf to the homepage. But when i start going to other pages like http://-ip-adress-*/test * it gives me a 404 Not found errorpage. After going trough some forums i think it has something to do with my apache configuration and the modrewrite rule. So i will provide all the files i edited to try and fix this :

*.htacess file in public folder : *

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews

    RewriteEngine On
    RewriteBase /var/www/gloops/public/
   # change above to your site i.e.,  RewriteBase /whatever/public/

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

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

*apache2.conf file in /etc/apache2 : *

ServerName localhost

Mutex file:${APACHE_LOCK_DIR} default
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf

<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied

<Directory /usr/share>
        AllowOverride None
        Require all granted

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted

<Directory /var/www/gloops/public>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted

*000-default.conf in etc/apache2/sites-enabled : *

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/gloops/public
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
4 answers


Because AllowOverride is set to None, Apache will ignore every .htaccess file that it finds. Set it to All and your rewrite rules should now work as expected:

<Directory /var/www/gloops/public>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted

In addition, make sure that the rewrite module is enabled:

sudo a2enmod rewrite

Make sure you restart Apache after editing a configuration file or enabling a new module so that the changes take effect.

Thanks. Thanks.

It is working now.

I spent so much time for fixing this issue, finally you helped me.

I’m having a similar issue.. my POST request do not work from the chrome browser but works in all other browsers. I get a 404 bad request. go to this page ( in chrome and just click the search button

I’ve done Enabling mod_rewrite and it works now. FYI, I only followed the Step 1 and and it works, since laravel has it’s own .htaccess file.
sudo a2enmod rewrite
sudo systemctl restart apache2

by Mateusz Papiernik
by Brian Hogan
Apache's mod_rewrite module lets you redirect URLs based on additional conditions, or rewrite URLs in a cleaner fashion, translating human-readable paths into code-friendly query string. In this tutorial, you'll enable `mod_rewrite` and use `.htaccess` files to create a basic URL redirection, and then explore a couple of advanced use cases.