gpt4 book ai didi

linux - 同一服务器上的两个不同项目(不同的index.php)

转载 作者:太空宇宙 更新时间:2023-11-04 03:32:18 25 4
gpt4 key购买 nike

我正在尝试在同一台服务器上运行两个不同的 php 框架。要使用的框架由 uri 中的第一个路径确定。

例如:

http://www.example.com/v1/requestname

将转到位于以下位置的index.php:

/var/www/html/api/api

其他所有内容 ( http://www.example.com/v2/requestname ) 将转到位于以下位置的 index.php:

/var/www/html/api2/public

这是我的 apache 2.2 配置:

Alias /v1 /var/www/html/api/api
<Directory /var/www/html/api/api>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
</Directory>

DocumentRoot "/var/www/html/api2/public"
<Directory "/var/www/html/api2/public">
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
</Directory>

我一直在尝试使用 apache 来做到这一点,但是每个请求都被路由到 api2。我正在寻找的一切似乎都表明这应该有效。

最佳答案

这是我为将来的任何人想出的解决方案:

设置以/v1 开头的任何内容以发送到 API 的第一个版本。

Alias /v1 /var/www/html/api/api/index.php

将其他所有内容发送到第二个版本:

DocumentRoot "/var/www/html/api2/public"
<Directory "/var/www/html/api2/public">
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
</Directory>

诀窍是将index.php 添加到别名的末尾。

关于linux - 同一服务器上的两个不同项目(不同的index.php),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32831125/

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