Heim  >  Fragen und Antworten  >  Hauptteil

Konfigurieren Sie Rewrite-Regeln mit Apache auf demselben Server, um sowohl auf das Frontend als auch auf das Backend zugreifen zu können

Ich habe ein Vue.js-Projekt und ein Laravel-Projekt in Apache.

Ich habe Vue.js eingefügt C:/Apache24/htdocs/vue_project_name,把Laravel放在C:/Apache24/htdocs/laravel_project_name, damit ich die folgende Konfiguration erhalten kann:

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

Ich möchte tippen http://domain_name时重写URL,浏览器将直接跳转到http://domain_name/laravel_project_name。当我输入http://domain_name/api时,浏览器将直接跳转到http://domain_name/laravel_project_name/public/api.

Zum Beispiel habe ich eine API, die ich aufrufen kann http://domain_name/laravel_project_name/public/api/login来获取资源,但我希望简化为http://domain_name/api/login, um Ressourcen zu erhalten.

Wie implementiert man diese Funktion?

Dies ist meine httpd-vhosts.conf-Datei:

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

Ich weiß es, wenn ich http://domain_name时,Apache会直接跳转到http://domain_name/laravel_project_name tippe, etwa so:

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

Aber ich denke, dass sich dies auf den Backend-Pfad auswirken wird, daher brauche ich eine bessere Lösung.

Vielen Dank.

P粉946336138P粉946336138277 Tage vor455

Antworte allen(1)Ich werde antworten

  • P粉187160883

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

    Laravel必须指向<project_root>/public,这是你的问题...

    更新与Laravel相关的配置为DocumentRoot: "C:/Apache24/htdocs/laravel_project_name/public"

    我知道你正在使用Apache,但是看看如何将Nginx配置指向那个文件夹。

    Antwort
    0
  • StornierenAntwort