Laravel deployment on shared hosting – .htaccess rewrite rule

One problem I just ran into when I tried to deploy a Laravel app to my shared hosting service Siteground.
I copied my repo to a subdomain folder and ran the usual php and composer commands to set everything up.

But I had to use the url http://sub.domain.com/public to actually access the app’s public folder.
So after some digging around, I added the following lines to the .htaccess file in the subdomain directory:

<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]

</IfModule>

And everything worked great.

I guess in local dev environments like Laragon on windows or valet on MacOs, the programs automatically rewrites the path so I did not have to configure the .htaccess myself.

Leave a Reply

Your email address will not be published. Required fields are marked *