For a customer of mine I'm building a website. For this I use the Laravel framework. Now I know the best practice is to set the public directory as DocumentRoot, but the problem is, I can't. So I've done some research, and I saw that you could use .htaccess to handle this little problem. The snippet that's on the laravel forums is the following:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
But when I try this, I get a 500 Internal Server error. I found that the problem was the (.*)
part of the fourth line... But I just can't see what's wrong with it.
So does anybody know what's wrong with this snippet, why am I getting a 500 error...
You're almost there. REQUEST_URI
includes the leading slash /
. So you must say
RewriteCond %{REQUEST_URI} !^/public
Don't change the public folder path, just copy the usual laravel tree and use the following in /public/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
This worked for me on L3.