user4938195 user4938195 - 6 months ago 10
Linux Question

How to improve url in Laravel?

I created my app on Homestead. Everything works fine there. But when I moved app to an external server I always have to include index.php after root path.

Example:

www.domain.com/index.php/contact


How to I get rid of index.php to make my URL prettier?

Application is located:

/var/www/


Public directory is renamed to html:

/var/www/html


PS. I'm using apache2.

Answer

Assuming you already point your web server to public directory, your problem should be in your Apache conf.

Laravel comes out with .htaccess in public/.htaccess but you need to enable the mod rewrite in Apache for it to work

sudo a2enmod rewrite

For the .htaccess to work, you need to set the AllowOveride directive in Apache conf

<Directory "/var/www/public">
AllowOverride All
</Directory>
Comments