Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache htaccess将API重定向到子文件夹_Apache_.htaccess - Fatal编程技术网

Apache htaccess将API重定向到子文件夹

Apache htaccess将API重定向到子文件夹,apache,.htaccess,Apache,.htaccess,我的文档根目录(/var/www/html/)如下所示: app/ client/ index.html server/ api/ user/ get.php classes/ models/ 当用户导航到我的网站上任何不以api/开头的URL时,他们应该在客户端中加载index.html文件 RewriteCond %{REQUEST_FILENAME}

我的文档根目录(/var/www/html/)如下所示:

app/
    client/
        index.html

    server/
        api/
            user/
                get.php
        classes/
        models/
当用户导航到我的网站上任何不以
api/
开头的URL时,他们应该在
客户端
中加载index.html文件

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond ^ app/client/index.html [QSA,L]
该代码工作正常

但是,当URL以
api/
开头时,我希望将URL指向
server/
下的api文件夹

例如,
www.website.com/user
将加载index.html文件。 而
www.website.com/api/user/get.php
将加载
www.website.com/server/api/user/get.php

我知道在我的当前状态之前,我需要一个针对
api/
的特殊条件

重写规则^api应用程序/服务器/api[L]

该规则在使用
www.website.com/api
时有效,但在
api/
之后有斜杠时无效
www.website.com/api
->
www.website.com/app/server/api
www.website.com/api/test
->
www.website.com/var/www/html/test

有什么想法吗?

这样说:

RewriteEngine On

RewriteRule ^api(/.*)?$ app/server/api$1 [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond ^ app/client/index.html [L]
请确保在清除浏览器缓存后对其进行测试