Mod rewrite AngularJS+;PHP api

Mod rewrite AngularJS+;PHP api,mod-rewrite,Mod Rewrite,这是我的文件夹结构: myproject/ api/ api.php public/ .htaccess index.html scripts/ ... all my angular stuff... 我的.htaccess如下所示: RewriteEngine On # If an existing asset or directory is requested go to it as i

这是我的文件夹结构:

myproject/
    api/
        api.php
    public/
        .htaccess
        index.html
        scripts/
            ... all my angular stuff...
我的.htaccess如下所示:

RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]

RewriteRule ^/api/ ../api/api.php

# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html
所以,我想要这个:访问
http://localhost
只返回我的
index.html
。但是AngularJs脚本中对
/api/something
的Ajax调用应该由
api.php
文件处理


目前,我的Apache虚拟主机指向
myproject/public
。访问
http://localhost
工作正常(返回index.html),但我对
/api/something
的调用也会返回index.html。似乎从来没有到达过
api.php
。有什么想法吗

我不认为你能用双圆点解决问题,但你不能结束规则的处理

所以,在它匹配api之后,它将继续执行上一条规则并重写为index.html

在api行的末尾添加[L],如下所示:

RewriteRule ^/api/ ../api/api.php [L]
添加这个,因为它可能是必需的:),如果您想知道api.php中的“某物”是什么,您可以将其余部分或url(在api之后)作为参数传递

RewriteRule    ^api/(.+)$    <whatever_url_work>/api.php?action=$1    [NC,L]
RewriteRule^api/(.+)$/api.php?操作=$1[NC,L]

我不认为你能让双圆点起作用,但你不能结束规则的处理

所以,在它匹配api之后,它将继续执行上一条规则并重写为index.html

在api行的末尾添加[L],如下所示:

RewriteRule ^/api/ ../api/api.php [L]
添加这个,因为它可能是必需的:),如果您想知道api.php中的“某物”是什么,您可以将其余部分或url(在api之后)作为参数传递

RewriteRule    ^api/(.+)$    <whatever_url_work>/api.php?action=$1    [NC,L]
RewriteRule^api/(.+)$/api.php?操作=$1[NC,L]

正如我所怀疑的,当你点击apache时,相对论是不起作用的,请看下面这篇文章,以获得一个可能的解决方案。/api:Cool。我到家后会试试的。谢谢正如我所怀疑的那样,当您使用apache时,相对论是不起作用的,请参阅本文,以获得../api:Cool的可能解决方案。我到家后会试试的。谢谢