I have a Laravel project which was moved from custom VPS into shared hosting.
Rewrite all from root to the public was easy part.
But when i go to the domain.com/public page works…
So how i rewrite domain root to the public, but redirect direct acces to the domain.com/public back to the domain.com/ ?
Disclaimer:
There is plenty threads about Laravel and rewrite to the public folder. But no one works as expected.
2
Answers
I found solution so i want to share it with others.
Because most shared hosts do not let you change the directory of the main domain, this is a common problem. With Laravel, you must point the domain to the public folder.
While it is possible, be aware that with this solution you would be playing whack-a-mole with security issues were the app to ever update, as noted by @Tpojka you might be at risk of leaking secrets such as from your .env file.
A better solution which was described in this answer is to move the Laravel app directory somewhere else and either copy or symlink the public/ folder contents. This way the app’s actual files are not publicly accessible. You will need to make sure if you need to symlink storage/ that you move it to the proper document root as well.