Regex 如何将对index.php的请求重写到父目录

Regex 如何将对index.php的请求重写到父目录,regex,apache,.htaccess,symfony,mod-rewrite,Regex,Apache,.htaccess,Symfony,Mod Rewrite,我的网站有两个.htaccess文件,一个在projects根目录下,另一个在/Project root/Public/目录下,我想将直接请求重写为“http://localhost/Project Root/index.php“to”http://localhost/Project Root/“我该怎么做 我当前的.htaccess: 项目根目录.htaccess: RewriteEngine on RewriteCond %{REQUEST_URI} !^public RewriteRule

我的网站有两个.htaccess文件,一个在projects根目录下,另一个在/Project root/Public/目录下,我想将直接请求重写为“http://localhost/Project Root/index.php“to”http://localhost/Project Root/“我该怎么做

我当前的.htaccess:

项目根目录.htaccess:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
/项目根目录/Public/.htaccess

RewriteEngine On

RewriteCond %{THE_REQUEST} \s(?:/+(.+/))?public/ [NC]
RewriteRule ^ /%1 [L,R=301,NE]

DirectoryIndex index.php

<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
    RewriteRule .* - [E=BASE:%1]

    RewriteCond %{HTTP:Authorization} .+
    RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]

    RewriteCond %{ENV:REDIRECT_STATUS} =""
    RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 307 ^/$ /index.php/
    </IfModule>
</IfModule>
重新编写引擎打开
RewriteCond%{THE_REQUEST}\s(?:/+(.+/)?public/[NC]
重写规则^/%1[L,R=301,NE]
DirectoryIndex.php
选项-多视图
重新启动发动机
RewriteCond%{REQUEST_URI}:$0^(/.+)/(.*):\2$
重写规则。*-[E=基:%1]
RewriteCond%{HTTP:Authorization}+
重写规则^-[E=HTTP\U授权:%0]
RewriteCond%{ENV:REDIRECT_STATUS}=“”
重写规则^index\.php(?:/(.*)|$)%{ENV:BASE}/$1[R=301,L]
重写cond%{REQUEST_FILENAME}-F
重写规则^%{ENV:BASE}/index.php[L]
重定向匹配307^/$/index.php/

让您的
项目根目录.htaccess
如下所示:

重新编写引擎打开
RewriteCond%{THE_REQUEST}\s/+([^/]+/)?index\.php[?\s][NC]
重写规则^/%1[L,R=301,NC,NE]
重写规则。*公共/$0[L]
确保在测试之前清除浏览器缓存