Imran Khan Imran Khan - 1 year ago 90
Apache Configuration Question

Best way to remove public and index.php from Laravel 5 URLS

As i am new to laravel, i have installed a fresh copy, give necessary permissions and run the application everything is good.
Now i have create a virtual host in apache to remove the public, which is also working fine:

<VirtualHost *:80>
ServerName mobileapp

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/mobileapp/public
<Directory "/var/www/html/mobileapp/">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all

ErrorLog ${APACHE_LOG_DIR}/mobileapp_error.log
CustomLog ${APACHE_LOG_DIR}/mobileapp_access.log combined

Now the site can access locally through http://mobileapp/index.php/pages, but not working if i remove index.php from url (http://mobileapp/pages).
My .htaccess file is:

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

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^ index.php [L] # <----- Tested not working
RewriteRule ^(.*)$ /$1 [L] # <----- neither this one

I have also enable mode_rewrite. Can any one tell me what is the best and easy way to ride on this.

Answer Source

Try this front controller rule:

RewriteRule ^index\.php(/|$) - [L,NC]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)/?$ index.php/$1 [L]