Random thoughts & observations

From the mundane to the profound and everything in between here’s what’s rocking our world

Configuring Laravel 4 htaccess rules on a remote host

Posted: November 3, 2013
Written by: Saints At Play
Category: Laravel

We've recently been developing with Laravel 4 and hit some issues with getting the apache mod_rewrite rules to work when transferring a website from our local development server to the remote server.

After many headaches and roadbumps along the way here's how we resolved that issue.

  1. Remove ALL of the following - app, bootstrap and vendor directories and server.php file and place them in the root of the server (OUTSIDE of the publicly accessible web root - VERY important from a security perspective)
  2. Remove the following directories: packages and all your images, stylesheets, javascript files and other related assets from the laravel public directory and place those in the web root (public_html directory on our particular unix server)
  3. Finally, assuming your routes are defined correctly and working on the local development server then try using the following htaccess redirect rules:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [NC,L,QSA]

After numerous headaches and issues trying to find the htaccess rules to work those were the ones that we found that worked for us!

Hopefully our experiences and what we learned in the process will help anyone struggling with getting Laravel 4 to work on a remote server :)

« Return to Posts

Comments

There are no comments

Posting comments after three months has been disabled.