skip to Main Content

i have a Laravel project, and i have deployed it on Hostinger as a shared host,

my shared host structure :


[public_html] -> [contains all the files of laravel project also public of laravel]

[public_html] -> [contains .htaccess beside laravel project]

enter image description here


[.htaccess beside laravel project contains this] ->

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

the problem is

now everything working correctly but the problem is i have /public after my domain

it should be www.domain.com/
but i get www.domain.com/public/

but also i can go to www.domain.com/login
also i can go to www.domain.com/public/login

but i can not go to www.domain.com/

it redirects me back to www.domain.com/public/

how to solve it ? please

2

Answers


  1. Good day; for your website to work without /public

    1. Put all your code outside public_html (name the folder anything)
    2. Put only your public folder inside your public_html
    3. Edit your domain to face public_html, I think this is currently set based on your explanation.
    4. Edit index.php inside the public folder (e.g. public_html/public/index.php)
    5. Set reference to bootstrap.php and autoload.php to reference your code folder outside of public_hmtl

    An example is given below change (project_dir) to the directory you create the same level as public _html

    require DIR.’/../(project_dir)/vendor/autoload.php’; // probably line 34

    $app = require_once DIR.’/../(project_dir)/bootstrap/app.php’; //probably line 47

    You might also need to set the permission for the public folder to 775 but this is not neccesary

    Login or Signup to reply.
  2. The safest and simplest method is to use symlinks.

    First, create a new directory outside public_html. I follow the practice of /home/username/domainname

    Next delete your public_html directory

    Now create a symlinks from /home/username/domainname/public to /home/username/public_html

    The command would be

    ln -nfs /home/username/domainname/public /home/username/public_html
    

    And that’s it, your full application code will be in the domainname directory while only the contents of the public directory will be in public_html

    The main benefits of this approach is

    • Zero code changes
    • .env, vendor directory not accesible to the public increasing security
    • Easy to deploy, just deploy any changes to domainname directory and changes will automatically reflect
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search