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

Randy_Johnson's avatar

.htaccess Accessing from public_html

Hi, I am uploading a project using shared hosting (hostinger) and in a previous project I had it where I transferred the public folder into the public_html. After reading a post, a gentleman kindly says that its much better to have a .htaccess inside the public_html folder, pointing to the public/index.php (I think) in such as way as one can imagine like so. ../laravel/public/index.php.

The user describes using as such:

	RewriteCond %{HTTP_HOST} ^your-domain.com$ [NC,OR]
  	RewriteCond %{HTTP_HOST} ^www.your-domain.com$
  	RewriteCond %{REQUEST_URI} !your-laravel-folder/public/
  	RewriteRule (.*) /your-laravel-folder/public/ [L]

But my confusion is how to implement this into the file that is already there, which I have moved from /laravel/public to /public_html

Here you can see how the file system is laid out.

└── school-tools.online
    ├── laravel
    └── public_html
<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}]

    # 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]
</IfModule>

0 likes
5 replies
jlrdw's avatar

@randy_johnson on shared hosting you either need to:

  • Point to public as document root as per the documentation

Or

  • Have main laravel outside of puplic_html

I use this from snapey site http://novate.co.uk/deploy-laravel-5-on-shared-hosting-from-heart-internet/

But just suggestions.

Edit:

Your question about htaccess is: You can have two, the one in root is to direct all to public. The one in public is not altered. This is only for times like a shared host when you can't setup a virtual host.

Again all here is just suggestions.

1 like
Snapey's avatar
Snapey
Best Answer
Level 122

Its much better to just install your application then delete the public_html folder

Then create a symbolic link pointing public_html to the Laravel public folder.

As seen on one of my client sites on Hostinger.

Done.

1 like
Randy_Johnson's avatar

Yes, this was genius. How it has never come up before on search's I have no idea. Many thanks.

laracoft's avatar

@randy_johnson

The correct, secured Laravel folder structure should be:

└── blogapp             <- 1. Laravel root folder, DocumentRoot CANNOT point here
    ├── public          <- 2. DocumentRoot MUST point here, i.e. https://yourdomain.com
    │   └── robots.txt  <- 3. MUST be able to load https://yourdomain.com/robots.txt
    ├── .env
    ├── storage
    ...
    └── vendor

If for whatever reason you must follow the tutorial found here http://novate.co.uk/deploy-laravel-5-on-shared-hosting-from-heart-internet/

Then please structure them this way

├── public_html         <- 2. DocumentRoot MUST point here
│   └── blog            <- 3. move and rename `public` as `blog`, https://yourdomain.com/blog
│       ├── robots.txt  <- 4. MUST be able to load https://yourdomain.com/blog/robots.txt
│       └── index.php   <- 5. Must modify this index.php
└── blogapp             <- 1. Laravel root folder, DocumentRoot CANNOT point here
    ├── .env
    ├── storage
    ...
    └── vendor
1 like
Snapey's avatar

You NEVER need to alter the index.php file. Use a symlink instead.

The web server wants to serve public_html as its document root. Just change this into a symlink of the public folder.

1 like

Please or to participate in this conversation.