Maison  >  Questions et réponses  >  le corps du texte

Configurez les règles de réécriture avec Apache sur le même serveur pour pouvoir accéder à la fois au frontend et au backend

J'ai un projet Vue.js et un projet Laravel dans Apache.

J'ai mis Vue.js dans C:/Apache24/htdocs/vue_project_name,把Laravel放在C:/Apache24/htdocs/laravel_project_name pour pouvoir obtenir la configuration suivante :

虚拟主机文档根目录:"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"

Je veux taper http://domain_name时重写URL,浏览器将直接跳转到http://domain_name/laravel_project_name。当我输入http://domain_name/api时,浏览器将直接跳转到http://domain_name/laravel_project_name/public/api.

Par exemple, j'ai une API que je peux appeler http://domain_name/laravel_project_name/public/api/login来获取资源,但我希望简化为http://domain_name/api/login pour obtenir des ressources.

Comment implémenter cette fonction ?

Voici mon fichier httpd-vhosts.conf :

<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>

Je sais quand je tape http://domain_name时,Apache会直接跳转到http://domain_name/laravel_project_name, comme ceci :

<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>

Mais je pense que cela affectera le chemin backend, j'ai donc besoin d'une meilleure solution.

Merci.

P粉946336138P粉946336138277 Il y a quelques jours452

répondre à tous(1)je répondrai

  • P粉187160883

    P粉1871608832024-01-17 11:29:04

    Laravel doit pointer vers <project_root>/public, c'est ton problème...

    Mise à jour de la configuration liée à Laravel vers DocumentRoot: "C:/Apache24/htdocs/laravel_project_name/public".

    Je sais que vous utilisez Apache, mais voyez comment pointer la Nginxconfiguration vers ce dossier.

    répondre
    0
  • Annulerrépondre