38

Example:

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

To view the route above, I must navigate to public/index.php/get.

I've viewed quite a few SO posts and googled around trying different things and it hasn't made a difference (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 causing this still? I'm running Ubuntu.

user3817533
  • 639
  • 3
  • 11
  • 17

7 Answers7

101

Two most common causes of this behavior are:

  1. mod_rewrite not enabled

    sudo a2enmod rewrite && sudo service apache2 restart

  2. AllowOverride is set to None, set it to All, assuming Apache2.4

    sudo nano /etc/apache2/apache2.conf

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

peter.babic
  • 3,214
  • 3
  • 18
  • 31
  • There is no in my apache2.conf. An ls of /etc/apache2: root@none:/etc/apache2# ls apache2.conf conf.d mods-available sites-enabled apache2.conf.dpkg-dist envvars mods-enabled conf-available httpd.conf ports.conf conf-enabled magic sites-available root@none:/etc/apache2# – user3817533 Jul 16 '14 at 15:42
  • Yeah it is inside the apache2.conf file. But your problem got resolved already. Have a nice day! – peter.babic Jul 16 '14 at 15:52
  • I just enable rewrite_module and worked like a charm! – Memonic Jul 16 '14 at 16:23
  • 4
    This helped me out even a year and a half later. Thanks! :) – applecrusher Feb 20 '16 at 08:20
  • You should really override `AllowOverride` in the VirtualHost configuration found in `/etc/apache2/sites-available`. – Robert Brisita Aug 14 '18 at 15:50
42

Do you have mod_rewrite installed and enabled on apache? Try to remove the if lines ( and ) and see if it throws an error when you try to load the website. If it does, run sudo a2enmod rewrite and restart apache.

This is the .htaccess I have on 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>
Eduardo Reveles
  • 2,155
  • 17
  • 14
  • sudo a2enmod rewrite perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LANG = "en_US.UTF-8" are supported and installed on your system. perl: warning: Falling back to the standard locale ("C"). Module rewrite already enabled I'm not sure if I do have it enabled... Where can I do that? – user3817533 Jul 16 '14 at 15:35
  • It seems it's installed and enabled. "Module rewrite already enabled". Can you try using my .htaccess? – Eduardo Reveles Jul 16 '14 at 15:36
6

In the Apache Configuration file may be located at /etc/httpd/conf/httpd.conf (location and names varies on server), provide AllowOverride permission for .htaccess file by updating the directory as follows:

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

This may solve your problem on laravel routes.

Also ensure that you're providing access "AllowOverride All" limited to directories, such as mentioned above and limited to the directory /var/www/laravel-sample-project/public (mentioned here is the root directory for my project which may varies for you)

Tantrik
  • 71
  • 1
  • 4
5

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

Juri Noga
  • 4,363
  • 7
  • 38
  • 51
Mr CaT
  • 337
  • 3
  • 4
3

I know it's an old question, but for people coming from search engines:

Although the apache site config I had enabled (/etc/apache2/sites-enabled/sitename.conf) had AllowOverride All

But for some reason the /etc/apache2/apache2.conf file had AllowOverride None for /var/www/ directory.

Solution:

  1. Run nano /etc/apache2/apache2.conf
  2. Find Directory /var/www/ (on mac you can ctrl+w, paste the text and hit enter)
  3. Inside it, change AllowOverride None to AllowOverride All

So, this

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

becomes this:

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>
Rizwan
  • 290
  • 1
  • 5
  • 15
0

If you do not use a .htaccess file, you need to specify the directory for your redirections:

  <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>
JVitela
  • 2,472
  • 2
  • 22
  • 20
  • Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator at webmaster@localhost to inform them of the time this error occurred, and the actions you performed just before this error. – Mohamed Raza Jan 18 '22 at 22:23
  • @MohamedRaza check the syntax of your Apache config (apachectl configtest) and that the routes you entered are valid. – JVitela Mar 18 '22 at 10:35
  • where can i check the syntax of apache config? – Mohamed Raza Mar 18 '22 at 11:20
0

In MacOs. The Main problem of .htaccess not working is there is not mod_rewrite.so enabled in httpd.conf file of apache configuration. i have solved this by uncomment the line :

LoadModule rewrite_module libexec/apache2/mod_rewrite.so

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

Community
  • 1
  • 1