Htaccess mod 重写不起作用

Htaccess mod rewrite don't work

我有一个包含两个应用程序的项目:一个前端(在 AngularJs 中)和一个后端(在 Phalcon 中)。我的服务器文档根目录有两个文件夹和一个 htaccess:

public_html
 - api
     - controllers
     - index.php
 - app
 - .htaccess

.htaccess 有下一个配置:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^api/(.*)$ api/index.php?_url=/ [QSA,L]
</IfModule>

RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

因此,当我向 http://mydomain/api/sessions 发送 POST 请求(例如)时,结果是 404 not found。路由器配置为:

$router->addPost('/sessions', array(
    'controller' => 'sessions',
    'action' => 'post'
));

在我的本地主机上,此配置工作正常。但是,在我的 VPS 中没有。 有什么想法吗?

更新 1:

如果我不使用任何 REST 服务,则通过 http://mydomain/api 访问 Phalcon 索引控制器已加载。

更新二:

如果我尝试使用像 http://mydomain/api/index.php?_url=/licenses 这样的 Phalcon url 来访问 REST 服务,那么工作正常。

您有时可以在文档根目录中使用相对路径替换,但是,您应该使 RewriteRule 替换根目录相对(以斜杠开头),或指定 RewriteBase / 指令在启用重写引擎以明确指定 URL 前缀之后。

RewriteRule ^api/(.*)$ api/index.php?_url=/ [QSA,L]

变为:

RewriteRule ^api/(.*)$ /api/index.php?_url=/ [QSA,L]

我发现了问题。虚拟主机配置文件没有下一行:

<Directory "/var/www/domain/public_html">
   Options All
   AllowOverride All
   Allow from all
</Directory>