Alen
Alen

Reputation: 1788

Laravel pretty URLs and routing not working on LAMP

I created web app with Laravel, which I tested on laravel server ( php artisan serve ) and now I want to put it on LAMP so I can test it further, but something is wrong.

When I visit localhost/public/ I get my home page but when I click on any link inside my app I get Not found error. On the other side, when I manually input localhost/public/index.php/someURL then I get the linked page.

Can someone tell me how to fix this?

This is my .htaccess file inside public directory:

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

    RewriteEngine On

    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

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

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

<IfModule mod_deflate.c>
<FilesMatch "\.(html|php|txt|xml|js|css)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>

This is the content of apache2 conf file ( /etc/apache2/sites-available/000-default.conf ) :

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/

        <Directory "/var/www/html">
                AllowOverride All
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

And I enabled mod_rewrite with this command: sudo a2enmod rewrite

I'm using Ubuntu 14.04.

UPDATE:

App is placed inside /var/www/html/

Upvotes: 2

Views: 3081

Answers (2)

Alen
Alen

Reputation: 1788

This is how I fixed it. I created another .htaccess file and placed it in root directory /www/html/:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^public
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

Information taken from here: http://driesvints.com/blog/laravel-4-on-a-shared-host

Upvotes: 1

Manthan Thakar
Manthan Thakar

Reputation: 209

Go to /etc/apache2/apache2.conf file and make sure it looks like this:

<Directory /var/www/html>
  Options Indexes FollowSymLinks
  Allowoverride All
  Require All Granted   
</Directory>

You can locate it right after

<Directory /usr/share> 
.... 
</Directory>

Perform mod_rewrite and restart apache and it should work!

Upvotes: 6

Related Questions