I have a Vue.js project and a Laravel project in Apache.
I put Vue.js in C:/Apache24/htdocs/vue_project_name
and Laravel in C:/Apache24/htdocs/laravel_project_name
, so I can get the following configuration :
虚拟主机文档根目录:"C:/Apache24/htdocs/"。 前端URL:"http://domain_name/vue_project_name" 后端URL:"http://domain_name/laravel_project_name" 后端API URL:"http://domain_name/laravel_project_name/public/api"
I want to rewrite the URL when typing http://domain_name
, the browser will jump directly to http://domain_name/laravel_project_name
. When I type http://domain_name/api
, the browser will jump directly to http://domain_name/laravel_project_name/public/api
.
For example, I have an API that I can call http://domain_name/laravel_project_name/public/api/login
to get resources, but I want it to be simplified to http://domain_name/ api/login
to obtain resources.
How to implement this function?
This is my httpd-vhosts.conf file:
<VirtualHost *:80> DocumentRoot "C:\Apache24\htdocs" ServerName domain_name ErrorLog "C:\Apache24\logs\error.log" CustomLog "C:\Apache24\logs\access.log" combined <Directory "C:\Apache24\htdocs"> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>
I know that when I enter http://domain_name
, Apache will jump directly to http://domain_name/laravel_project_name
, like this:
<VirtualHost *:80> DocumentRoot "C:\Apache24\htdocs\vue_project_name" ServerName domain_name ErrorLog "C:\Apache24\logs\error.log" CustomLog "C:\Apache24\logs\access.log" combined <Directory "C:\Apache24\htdocs\vue_project_name"> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>
But I think this will affect the backend path, so I need a better solution.
Thanks.
P粉1871608832024-01-17 11:29:04
Laravel must point to <project_root>/public
, this is your problem...
Update the configuration related to Laravel to DocumentRoot: "C:/Apache24/htdocs/laravel_project_name/public"
.
I know you are using Apache, but take a look at how to point the Nginx
configuration to that folder.