Question

Why do my laravel routes not work?

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>

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.

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

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 (https://www.allmetrorealestate.com) in chrome and just click the search button