I use Laravel framework. As you know, its directory looks like this:
To open the homepage of my website (Route::get('/', 'HomeController@index');
) I need to open /public
folder of directory. In other word, to see the first page of my website, here is the URL:
http://example.com/public
anyway, only my domainname (http://example.com/
) isn't my root. How can I make /public
folder as root?
Curently I've found a workaround. I can create an index.php
on the root and write a redirect code to /public
folder. So when user enters http://example.com/
, it will be redirected to http://example.com/public
automatically. But still that's ugly. I don't like to see /public
in the URL. Any suggestion?
./config/filesystems.Modify the section 'public' to change the 'root' value 'app/public' to your desired location, for example, app/public_html ( app is an alias of your root folder).
By default in the Laravel app core, this directory is namespaced under App and it is autoloaded by Composer using the PSR-4 autoloading standard. The app directory has a variety of additional directories such as console, http, and providers.
Root is an admin package for Laravel applications.
The files and folders in laravels public folder are meant to be web accessible. For security, all other files and folders in the laravel framework should not be web accessible. Moving the index. php to laravels root will break the framework and defy best practices.
Do not mofidy any Laravel files. Use web server (Apache or Nginx) to point Laravel project to public
directory.
For Apache you can use these directives:
DocumentRoot "/path_to_laravel_project/public"
<Directory "/path_to_laravel_project/public">
For nginx, you should change this line:
root /path_to_laravel_project/public;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With