Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

JohanCorn's avatar

Root redirect to public folder

My laravel application is installed on a shared host webserver. I cannot changed the main entry point so it must be the root. By default for security reasons it is not recommended to copy all files to the root from public directory.

I decided to redirect the request from the root into the public folder using .htaccess

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

The application based pages working fine with this redirection but the static files like /build/assets/anything.js or css files are cannot be found even they are.

I think it is because of the redirection but I can't resolve the problem.

Any idea? Thanks!

0 likes
2 replies
gych's avatar

Move all files from inside the public folder to the document root. Then update the requires in the index.php to point to your laravel application folder outside of the public root.

Please or to participate in this conversation.