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

标签 linux apache centos mod-alias

我正在尝试在同一台服务器上运行两个不同的 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/

相关文章:

linux - Openfire 进程不遵循 limits.conf 中的 ulimit nofiles 值

linux - Jenkins 在验证颠覆时出错

linux - 从 Apache/Nginx Access.log 检索用户代理

apache - 如何在 Centos 7 中更改虚拟主机的 apache 用户?

php - 将 cron 配置为每 15 分钟运行一次 URL

linux - 提交时 SVN 校验和错误

linux - 更改tomcat服务器端口的命令

php - 如何选择php运行在哪个用户?

linux new/delete, malloc/free 大内存块

php - mod_rewrite {QUERY_STRING}