将$_GET与htaccess或PHP一起使用时,请删除public


Remove public when using $_GET with htaccess or PHP

我正在学习创建自己的PHP MVC框架。这是我的URL结构:http://www.mvc.dev/public/controller/methold/params

我正在使用以下函数来获取当前URL。以下函数返回public/test1/test2/test3。我不想让public出现。

function parseUrl(){
  if( isset($_GET['url']) ){
    echo $_GET['url'];
  }
}

.htaccess将URI转换为查询字符串

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    RewriteBase /public
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>

请帮助,我如何从public/test1/test2/test3中删除public

DocumentRoot(高于public的级别)中创建this.htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]

然后您可以使用链接作为http://www.mvc.dev/controller/methold/params