Apache htaccess将API重定向到子文件夹
我的文档根目录(/var/www/html/)如下所示: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}
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]
请确保在清除浏览器缓存后对其进行测试