A Better .htaccess File For Laravel

By Phillip Harrington on 9/28/2016


When I'm developing on Windows, I always have to change the default, out of the box Laravel .htaccess file. Could just be the way Apache is set-up on my local system, but anyway… here it is. No breakdown or reason why this works, but… I'm just gonna leave this here.

Options -MultiViews

RewriteEngine On

# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

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

# Thanks! http://www.zeilenwechsel.de/it/articles/8/Using-mod_rewrite-in-.htaccess-files-without-knowing-the-RewriteBase.html
RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)\1$
RewriteRule ^.*$ %2index.php [QSA,L]