2

I moved Laravel's public folder to the root folder, and I moved Laravel to its own folder. So I can use Laravel on a shared hosting. It looks like this:

2015/08/04  18:13    <DIR>          .
2015/08/04  18:13    <DIR>          ..
2015/08/01  17:50               896 .htaccess
2015/07/29  17:39                 0 favicon.ico
2015/07/29  17:39             1,844 index.php
2015/08/04  17:19    <DIR>          laravel
2015/08/04  17:20    <DIR>          public
2015/08/01  17:46             1,165 README.md
2015/08/01  16:18                34 robots.txt
2015/08/04  17:20    <DIR>          static

For example, I'm using public_path() and I get this:

/htdocs/laravel/public

but what I need is this:

/htdocs/public

I've checked config files in /config/ but there is nothing about it.

Please tell me how to fix it. thx

(My laravel version is 5.0.33)


PS: I've tried this method: Laravel 5 on shared hosting - wrong public_path()

I overwrited public_path() in AppServiceProvider

$this->app->bind('path.public', function() {
    return base_path() . '/';
});

But nothing changed.

Community
  • 1
  • 1
Abel
  • 21
  • 1
  • 1
  • 4

2 Answers2

3

you can bind the public folder correctly by adding this to the index.php file in usually found in your /public folder

// set the public path to this directory
$app->bind('path.public', function() {
    return __DIR__;
});

You may want to clear your cache after this as the paths may have been cached before. The cached config can be located and deleted manually if you don't have ssh access to the server at bootstrap/cache/config.php

Emeke Ajeh
  • 933
  • 1
  • 10
  • 16
2

Instead of moving the public folder, try to add a .htaccess in your root with the following content :

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

This will redirect all the requests to /public

Mush
  • 153
  • 1
  • 1
  • 8