this is NEVER a good idea and such articles should be marked as dangerous
you risk exposing all your .env secrets
Laravel is not designed to be installed in such a way
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, i followed a guide on how to setup an .htaccess to redirect from root to public folder on a server, after creating .htaccess on root, tweaking the code because all the project is inside a subfolder and trying it on XAMMP, every route works like its suppoused to like testwebsite.test/login , but if i try to enter testwebsite.test/ the URI changes to testwebsite.test/subfolder_name/public/subfolder_name/public/.
It still works and properly shows '/' route, but i dont know why the URI change happens and if i try to refresh the page it throws a 404 as there is no /subfolder_name/public/subfolder_name/public/ route, obviously.
My guess is that the .htaccess on /public doesnt know how to handle if its a redirect from another .htaccess but i dont have much knowledge of this subject so i can't solve it on my own thats why im asking for help.
<IfModule mod_rewrite.c>
# That was ONLY to protect you from 500 errors
# if your server did not have mod_rewrite enabled
RewriteEngine On
# RewriteBase /
# NOT needed unless you're using mod_alias to redirect
RewriteCond %{REQUEST_URI} !/subfolder_name/public
RewriteRule ^(.*)$ subfolder_name/public/$ 1 [L] // 1 is next to $ in code but laracasts hides them if they are together for some reason
# Direct all requests to /public folder
</IfModule>
(the whole projects needs to be on subfolder_name subfolder so it isnt public, the original code on the guide was RewriteCond %{REQUEST_URI} !/public instead of RewriteCond %{REQUEST_URI} !/subfolder_name/public and RewriteRule ^(.*)$ public/$1 [L] instead of RewriteRule ^(.*)$ subfolder_name/public/$1 [L])
Guide link: https://dev.to/vumanhtrung/setup-an-htaccess-file-for-redirecting-to-laravel-s-public-folder-1e1j
Please or to participate in this conversation.