Skip to content

Instantly share code, notes, and snippets.

@egyjs
Last active June 5, 2020 05:48
Show Gist options
  • Save egyjs/704b8bc54aaa23067b4d325cfe29e512 to your computer and use it in GitHub Desktop.
Save egyjs/704b8bc54aaa23067b4d325cfe29e512 to your computer and use it in GitHub Desktop.
Laravel 5-6 – Remove Public from URL
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]

DON'T!

YOU REALLY SHOULD NOT rename server.php in your Laravel root folder to index.php and copy the .htaccess file from the /public directory to your Laravel root folder!!!

This way everyone can access some of your files (.env for example). Try it yourself. You don't want that!


DO

Instead, you should create an .htaccess file in your root like this:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]

This will silently rewrite all your base URIs to the /public folder. Even all Headers, for example the HTTP Authorization Header, and all optional URI parameters will silently be passed on to the /public folder as well.

That's all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment