简体   繁体   中英

Laravel: Put index.php in a subfolder of public folder

I have singlepage app at https://example.com . App's api and backend is driven by laravel. Can someone point me to the right direction how to open my spa at: https://example.com and backend at https://example.com/backend

What I've tried:

  1. I've put all my files of SPA in public folder and move laravel public files (including .htaccess and index.php) in public/backend folder

  2. Changed the public path of laravel to public/backend

This gives me Internal Server Error when access https://example.com/backend

Thanks in advance!

In case you want your SPA served via Laravel

Edit your routing so the api group is changed to backend . Then create a route in the web group for / which loads a blade template containing your vue components and vue router. The vue router will handle the SPA page loads after its loaded.

In case you want your SPA served separately from Laravel

In this case you'll have an entry point for your backend which is index.php . And you'll have an entry point for your SPA which will be index.html . I would advice you to keep your index.php in the /public folder of our Laravel installation. Then change the way index.html is compiled so it's placed in a different folder, lets say /build . You can probably achieve this by adjusting some webpack or vue-cli settings. Then adjust your webserver configuration (apache/nginx) so it will have the following two entries:

  1. https://example.com/backend which maps to /var/www/{project}/public
  2. https://example.com/ which maps to /var/www/{project}/build

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM