【发布时间】:2016-01-02 22:35:14
【问题描述】:
我在 80 端口运行 apache Web 服务器,在 5000 端口运行烧瓶应用程序。
我需要处理以下 URL 并相应地指向它们的端口。
http://hello_world.com/api/v1/en/user/register
http://hello_world.com/api/docs/
http://hello_world.com
我需要做的是
如果 URL 是 http://hello_world.com,请将其指向我在 index.php 中的 code_igniter 路由器。
如果 URL 是 http://hello_world.com/api/docs/,请不要指向 code_igniter,直接访问该文件夹。
如果 URL 是 http://hello_world.com/api/v1/en/user/register,请将其指向我的烧瓶应用程序的 5000 端口。
我有以下 conf 文件。但是,当我尝试 ProxyPass 到端口 5000 时,我不断收到 404 错误。
File does not exist: /var/www/api/v1
但是,我的烧瓶应用程序路由器应该路由该 /api/v1/... URI。
我的 conf 看起来像
<VirtualHost *:80>
ServerAdmin admin@hello_world.com
ErrorDocument 404 /index.php
# Rewrite for Code Igniter if the URI doesn't start with /api/
RewriteCond %{REQUEST_URI} !^/api/(.+)$
RewriteCond %{REQUEST_URI} !^(index\.php|robots\.txt|fonts|assets|uploads|images)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
# ProxyPass if the URI is /api/v1/
ProxyPreserveHost On
ProxyPass ^/api/v1/(.+)$ http://localhost:5000/api/v1/$1
ProxyPassReverse ^/api/v1/(.+)$ http://localhost:5000/api/v1/$1
DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options FollowSymLinks MultiViews
AllowOverride All
</Directory>
...
</VirtualHost>
【问题讨论】:
-
RewriteCond $1 !^/api/(.+)$中的$1是什么意思? -
@arkascha 是 %{REQUEST_URI}
-
应该怎样?你为什么不把
%{REQUEST_URI}放在那里? -
@arkascha,我尝试过使用 %{REQUEST_URI}。但是,它仍然无法正常工作。我会更新问题。
-
而 if 那
$1真的为你解析为%{REQUEST_URI}(我不知道它应该怎么做,但无论如何......),然后是第二个模式@ 987654332@ 永远不会匹配任何东西。您忘记了前导斜杠 (/)。但是无论如何它都不是必需的,因为我认为这些是现有文件或文件夹。
标签: apache .htaccess codeigniter