如何将对 index.php 的请求重写到父目录
How to rewrite requests to index.php to parent directory
我的网站有两个 .htaccess 文件,一个在项目根目录中,一个在 /Project Root/Public/ 目录中,我想将直接请求重写为“http://localhost/Project Root/index.php”到“http://localhost/Project Root/”我该怎么做?
我当前的 .htaccess(s):
项目根.htaccess:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/ [L]
/项目Root/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}::[=12=] ^(/.+)/(.*)::$
RewriteRule .* - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/ [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>
让你的Project Root .htaccess
像这样:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+([^/]+/)?index\.php[?\s] [NC]
RewriteRule ^ /%1 [L,R=301,NC,NE]
RewriteRule .* public/[=10=] [L]
确保在测试前清除浏览器缓存。
我的网站有两个 .htaccess 文件,一个在项目根目录中,一个在 /Project Root/Public/ 目录中,我想将直接请求重写为“http://localhost/Project Root/index.php”到“http://localhost/Project Root/”我该怎么做?
我当前的 .htaccess(s):
项目根.htaccess:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/ [L]
/项目Root/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}::[=12=] ^(/.+)/(.*)::$
RewriteRule .* - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/ [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>
让你的Project Root .htaccess
像这样:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+([^/]+/)?index\.php[?\s] [NC]
RewriteRule ^ /%1 [L,R=301,NC,NE]
RewriteRule .* public/[=10=] [L]
确保在测试前清除浏览器缓存。