gpt4 book ai didi

apache - 我如何让 Apache 知道哪个应用程序目录用于不同的域?

转载 作者:行者123 更新时间:2023-12-05 02:25:14 24 4
gpt4 key购买 nike

我正在尝试使用 CodeIgniter 创建一个站点。我将从该服务器提供多个域,我要做的是将 www.example1.com 的 HTTP 请求与 www.example2.com 的 HTTP 请求分开,然后将它们重定向到正确的应用程序文件夹。

假设这是我的目录结构:

  • 系统
    • 申请
      • 例子1
      • 例子2

所以这个请求

www.example1.com/gallery/

然后将被重定向到 exmaple1 文件夹。

有没有人有这样做的代码示例?显然你需要使用 ReWrite 模块......

我查看了 Apache 文档,但一无所获。如果您需要这方面的更多信息,请告诉我。

最佳答案

你需要的是VirtualHost使 www.example1.com 和 www.exaplme2.com 分别指向文件系统中的不同文件夹。

如果您还希望在 URI 中使用不同的路径来提供主要内容,您有多种选择:

  1. 物理创建文件夹并且不做进一步的更改

  2. 物理创建指向该文件夹的链接(名为 gallery 指向主虚拟主机根文件夹)并使用 FollowSymLinks VirtualHost 的选项

  3. 使用Alias VirtualHost 中的指令

    Alias /gallery /
  4. 使用 mod_rewrite

    RewriteRule /gallery/(.*) /$1 [QSA]

最简单的(CodeIgniter 允许)是选项 1 或 2。

VirtualHost 文档中的片段:

Running several name-based web sites on a single IP address.Your server has a single IP address, and multiple aliases (CNAMES) point to this machine in DNS. You want to run a web server for www.example.com and www.example.org on this machine.NoteCreating virtual host configurations on your Apache server does not magically cause DNS entries to be created for those host names. You must have the names in DNS, resolving to your IP address, or nobody else will be able to see your web site. You can put entries in your hosts file for local testing, but that will work only from the machine with those hosts entries.Server configuration# Ensure that Apache listens on port 80Listen 80# Listen for virtual host requests on all IP addressesNameVirtualHost *:80<VirtualHost *:80>DocumentRoot /www/example1ServerName www.example.com# Other directives here</VirtualHost><VirtualHost *:80>DocumentRoot /www/example2ServerName www.example.org# Other directives here</VirtualHost>The asterisks match all addresses, so the main server serves no requests. Due to the fact that www.example.com is first in the configuration file, it has the highest priority and can be seen as the default or primary server. That means that if a request is received that does not match one of the specified ServerName directives, it will be served by thisfirst VirtualHost.

关于apache - 我如何让 Apache 知道哪个应用程序目录用于不同的域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1025587/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com