Updated..
Before that, I suggest that using a sub-domain is a better solution than letting your Laravel app lives in sub-directory.
I have tried two methods
- Create .htaccess at root of your project to redirect to the public folder.
- Move all files in public folder to the root of your project and move all files in root of your project (excluded public folder) to the folder created by ourself. Lastly, re-point the autoload and app.php inside index.php.
both can be found online.
And both works very fine.
However, the problems I have faced are:
when you have gone far for your project.
every links or urls you have coded must be added with {your subdirectory name} .
(eg. form action in login.php "localhost/login" will be changed to "localhost/sub_dir_name/login)
because changing project to subdirectory, your laravel routing doesn't match the changed url anymore.
For the solution of these problems.
- All your routes in web.php (laravel 5.3) or routes.php ( 5.2 and below) must be grouped by prefix of "your sub directory name".
- Try to use laravel global helper class url() to every url like your css call, js call , form action. And modify url() function in directory vendor/laravel/framework/src/illuminate/foundation/helpers.php to add your subdirectory name automatically when calling url() function.
(However, changing your library file in vendor is not recommended. you should write your own helper class to wrap that function and write your own code for that. But in this case, you will be using your own helper class but not url() anymore).
tested with laravel 5.3 and xampp.
Maybe my solution is not the best, if you have a better solution. Please share with me.
[email protected]