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
P粉946336138
P粉946336138 2024-01-16 13:12:59
0
1
447

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粉946336138
P粉946336138

répondre à tous(1)
P粉187160883

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.

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!