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

mikkelbfriis's avatar

htaccess redirects to public

Hey, so I'm using Laravel on shared hosting for a customer I have, however everytime I visit my main URL it redirects me to /public/

<IfModule mod_rewrite.c>
   RewriteEngine On 
   RewriteRule ^(.*)$ public/ [L]
</IfModule>

I'm fairly certain the htaccess is not the issue, but I feel like I've tried everything.

I am unable to change my document root to public, which is also why I'm posting now, because I've seen that people suggest it, however not at option for me.

0 likes
4 replies
MichalOravec's avatar

This should work

<IfModule mod_rewrite.c>
   RewriteEngine On 

   RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
mikkelbfriis's avatar

I actually do have that, for some reason it didn't post the $1.

I'm so confused.

jlrdw's avatar

I use:

    RewriteEngine On
    RewriteRule ^(.*)$ public/
    RewriteRule ^ server.php

But I'd recommend having main laravel out of web root or web. Just a suggestion.

Above is development only, I separate main laravel in a host.

Snapey's avatar

This is not recommended and may come back on you if your customer gets their site hacked

make sure the .env file is not accessible to the public

Please or to participate in this conversation.