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

Mat's avatar
Level 1

Moving Laravel core in a subfolder of public

Hi all, I'm new :-)

With a hosting provider that I have to use for a project all web content is publicly available. So I moved the core contents in a subfolder (called "laravel") in this way:

  • Moved everything in laravel folder
  • Moved laravel/public/* in / (document root)
  • Updated index.php lines
require __DIR__.'/laravel/bootstrap/autoload.php';
$app = require_once __DIR__.'/laravel/bootstrap/app.php';
  • Created a laravel/.htaccess
<IfModule mod_rewrite.c>
    RewriteRule ^(.*)$ /httpdoc/$1 [L,R=301]
</IfModule>

All seems to work correctly... but I have little experience with Laravel.

  • Do I have to modify something else?
  • Do you see drawbacks with this method?
0 likes
5 replies
phildawson's avatar

I would recommend finding a better hosting provider which doesn't require all content to be publicly available.

Mat's avatar
Level 1

Thank you for your reply Phildawson but changing hosting provider is not an option with this customer now, that's why I wrote a message here. Some other framework (for example CakePHP) works well with everything on the public folder.

martinbean's avatar

@Mat You don’t need to move any files around. Just have a .htaccess file that rewrites any requests to public/index.php, just like CakePHP does ;)

Mat's avatar
Level 1

@martinbean: you are right :-) I missed the simple way, I'll do some tests. Thank you

Mat's avatar
Mat
OP
Best Answer
Level 1

Mmm... no, it's not so simple. If I remove "public" using mod_rewrite I get routing errors. I suppose that my current solution is the best one for now.

Please or to participate in this conversation.