Laravel routes do not work, Apache configuration only allows public / index.php / route

Example:

Route::get('/get', function() { return 'get'; }); 

To view the route above, I have to go to public / index.php / get.

I looked at quite a few SO posts and looked for different things, and that didn't change (yes, I restart Apache every time).

Here is my .htaccess in the public directory:

 <IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine On </IfModule> # For all files not found in the file system, reroute the request to the # "index.php" front controller, keeping the query string intact <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] </IfModule> 

What could be the reason for this? I am running Ubuntu.

+20
apache .htaccess laravel
Jul 16 '14 at 15:22
source share
6 answers

Is mod_rewrite installed and installed on apache? Try removing the if (and) lines and see if this causes an error when trying to load a website. If so, run sudo a2enmod rewrite and restart apache.

This is the .htaccess that I have in my public / directory:

 <IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On # Redirect Trailing Slashes... RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule> 
+20
Jul 16 '14 at 15:33
source share
— -

The two most common causes of this behavior are:

  • mod_rewrite is not enabled

    sudo a2enmod rewrite && sudo service apache2 restart

  • AllowOverride set to None, set it to All, assuming Apache2.4

    sudo nano /etc/apache2/apache2.conf

find <Directory /var/www/> and change AllowOverride None to AllowOverride All , then save the file and restart apache

+64
Jul 16 '14 at 15:39
source share

Changing AllowOverride None to AllowOverride All and sudo a2enmod rewrite && sudo /etc/init.d/apache2 reload really helped.

+3
Aug 14 '17 at 10:44 on
source share

If you are not using the .htaccess file, you need to specify the directory to redirect to:

  <IfModule mod_rewrite.c> RewriteEngine On <Directory /home/vitela/laravel/public> RewriteBase /public RewriteRule ^(.*)/$ /$1 [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php [L,QSA] </Directory> </IfModule> 
0
Jun 01 '15 at
source share

In MacOs. The main .htaccess problem does not work - mod_rewrite.so is not supported in the apache configuration httpad.conf file. I solved this by uncommenting the line:

LoadModule rewrite_module libexec / apache2 / mod_rewrite.so

Remove # from the httpdf.conf line above. Then it will work. enjoy it!

0
Aug 01 '17 at 9:09 on
source share

In the Apache configuration file, it can be located at /etc/httpd/conf/httpd.conf (location and names may vary on the server), grant AllowOverride permission for the .htaccess file, updating the directory as follows:

 <Directory "/var/www/laravel-sample-project/public"> AllowOverride All </Directory> 

This may solve your problem on Laravel routes.

Also make sure that you grant "AllowOverride All" access limited to directories such as those mentioned above and limited to / var / www / laravel-sample-project / public (the root directory for my project mentioned here, which may vary for you)

0
Sep 07 '19 at 9:33
source share



All Articles