Why do my laravel routes not work?

May 28, 2016 2.8k views
Apache PHP DigitalOcean LAMP Stack

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
    </IfModule>

    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]
</IfModule>

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

ServerName localhost

Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
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>

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

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

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

*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
</VirtualHost>
1 Answer

Hi!

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
</Directory>
...

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.

Have another answer? Share your knowledge.