Apache Slim 3-使用重写规则从url中删除子目录

Apache Slim 3-使用重写规则从url中删除子目录,apache,.htaccess,url-rewriting,slim-3,Apache,.htaccess,Url Rewriting,Slim 3,我在A2Hosting上有一个共享主机,最近我将我的主域从public\u html/移动到public\u html/subdir/ 结构如下: /public_html /subdir(site files of main domain) /api index.php 我当前的htaccess(public_html)是: 当我调用APi之前,它是:domain.com/APi/ 但现在是:domain.com/subdir/api/ 我在api中的htaccess是: Re

我在A2Hosting上有一个共享主机,最近我将我的主域从
public\u html/
移动到
public\u html/subdir/

结构如下:

/public_html
 /subdir(site files of main domain)
  /api
  index.php  
我当前的htaccess(public_html)是:

当我调用APi之前,它是:
domain.com/APi/

但现在是:
domain.com/subdir/api/

我在
api
中的htaccess是:

RewriteEngine On
RewriteBase /api/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
如何删除url中的“subdir”以保持我的api与前面一样?但是仍然使用我当前的htaccess将根指向我的子目录


谢谢

一种方法是从根目录中的主.htaccess文件重写
/api
,如下所示:

RewriteEngine On
RewriteBase /
RewriteRule ^api/(.*)$ ../subdir/api/$1 [R,L,QSA]
new/subdir/api文件夹中的.htaccess文件可以保持原样。只需要调整基础

另一种方法是,如果出于某种原因保留了上一个
/api
文件夹,则从该文件夹重写:

RewriteEngine On
RewriteBase /api
RewriteRule ^(.*)$ ../subdir/api/$1 [L]

我想你可以在apache配置文件easilyHi@zedling中更改基本路径,对不起,我忘了提到我在共享主机上我希望你没有将应用程序文件移动到public htmlHi@ZamronyP.Juhara下,你指的是哪个应用程序文件?我的所有文件都在子文件夹中。您在这里使用的是哪个版本的slim?可以显示index.php代码吗?
RewriteEngine On
RewriteBase /api
RewriteRule ^(.*)$ ../subdir/api/$1 [L]