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

basirafeef's avatar

How to publish Laravel projects in shared hosting like Siteground?

i have some problem redirecting users to Laravel public directory from the root of the project. i created the following .htaccess file at the Laravel root directory to redirect requests to the public directory, i want to conform that is this the correct way to do it ?

.htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Handle X-XSRF-Token Header
    RewriteCond %{HTTP:x-xsrf-token} .
    RewriteRule .* - [E=HTTP_X_XSRF_TOKEN:%{HTTP:X-XSRF-Token}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    RewriteRule ^ public/index.php [QSA,L]
</IfModule>

thanks.

1 like
5 replies
jlrdw's avatar

Main laravel should be one directory higher than public_html. But there are many good past answers covering how to set all of this up.

Search for an answer from @snapey where public_html replaces public.

1 like
basirafeef's avatar

Thanks, @Snapey sir! I read the complete guide, and it was exactly what I was looking for. I learned a lot from it.

However, are there other ways to deploy Laravel projects without modifying public_html or changing Laravel's default structure? For example, can I use .htaccess to achieve this?

In my Slim Framework projects, I simply used .htaccess to point to the public directory, and it worked fine. I'm wondering if something similar is possible in Laravel.

Thanks for your time, sir!

Please or to participate in this conversation.