【发布时间】:2019-07-31 06:55:40
【问题描述】:
我正在使用 php 构建一个应用程序,该应用程序提供 API 接口和 Web 应用程序 (HTML) 接口。我的文档根目录中的目录中都有这两个:
/www/sys/api 和 /www/sys/webapp
在每个目录中,我都有一个应该处理路由的路由器
/www/sys/api/public/api-index.php
/www/sys/webapp/public/webapp-index.php
现在我想做的是在我的/www/sys/ 中使用 .htaccess 文件以/www/sys/api/smth/smth/smth 的形式将任何请求路由到/www/sys/api/public/api-index.php?path=smth/smth/smth 和任何其他请求(www/sys/api 以外的任何请求,例如@ 987654328@ 或只是/www/sys/) 到/www/sys/webapp/public/webapp-index.php?path=smth。
现在我有这个:
RewriteEngine On
RewriteRule ^api/(.+)$ api/public/api-index.php?url=$1 [L]
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_URI} !^api/public/api-index.php
RewriteRule ^(.+)$ webapp/public/webapp-index.php?url=$1 [L]
这在某种程度上是有效的,除了:
转到 server/sys/api/ 将我发送到 server/sys/webapp/public/webapp-index.php 但如果我再添加一层 server/sys/api/hhh 就可以了!
如果我被重定向到 webapp,我没有得到完整的 url 参数,我总是得到 webapp/public/webapp-index.php,而在 API 中,我总是得到 public/api-inedx.php
总之,我需要获取此 .htaccess 以将 /sys/api/ 重定向到 /sys/api/api-index.php 并正确获取实际 url。提前致谢
【问题讨论】: