【问题标题】:Setting up a domain name for Frontend and Backend on XAMPP在 XAMPP 上为前端和后端设置域名
【发布时间】:2016-09-07 04:34:36
【问题描述】:

这是我第一次在 StackOverflow 上提问。

我有一个库系统,其中包括使用 php 的前端和后端。系统的文件结构有: 根目录:论文/ 前端:论文/前端/库/index.php 后端:论文/后端/base/index.php

我如何做到这一点,当您输入 www.example.com 时,它会将您重定向到前端,即 thesis/frontend/library/index.php,而当您输入 admin.example.com 时,它将重定向到后端这是论文/后端/base/index.php。

我以某种方式研究了一些东西并发现了创建虚拟主机。但无法做到这一点。

附: 前端在后端文件夹中获取资源(例如图像)。

【问题讨论】:

    标签: php html dns xampp


    【解决方案1】:

    将您的虚拟主机添加到xampp/apache/conf/extra/httpd-vhosts.conf

    # Frontend
    <VirtualHost example.com:80>
        DocumentRoot "D:/xampp/htdocs/thesis/frontend/library"
        ServerName example.com
    </VirtualHost>
    
    # Backend
    <VirtualHost admin.example.com:80>
        DocumentRoot "D:/xampp/htdocs/thesis/backend/base"
        ServerName admin.example.com
    </VirtualHost>
    

    现在您需要在 hosts 文件中添加记录以解析 127.0.0.1 中的 example.com

    打开您的主机文件C:\Windows\System32\drivers\etc\hosts 并添加

    127.0.0.1 example.com
    127.0.0.1 admin.example.com
    

    重启apache

    完成

    【讨论】:

    • 完成了,但是位于后端文件夹的图像在前端检索时不会加载。尝试了相对链接(../../backend/.....image.png)和直接链接(admin.example.com/.....image.png)
    • 您可以使用绝对路径从后端加载图片,http://admin.example.com/images/&lt;imagename&gt;
    猜你喜欢
    • 2021-02-14
    • 1970-01-01
    • 2013-02-25
    • 2021-02-06
    • 2021-01-06
    • 2023-03-22
    • 2020-11-28
    • 2016-04-09
    • 2021-05-06
    相关资源
    最近更新 更多