我无法通过 .htaccess 在重定向的 URL 中隐藏子文件夹


I can't hide the subfolder in my redirected URL by the .htaccess

我在这里看到了一些解决方案,但它们对我没有帮助。我的索引.php在这里:http://localhost/basic-2/web/index.php

我想的目标是 如果我输入http://localhost/basic-2 ,浏览器会将我重定向到http://localhost/basic-2/web/index.php路径,但在浏览器中,URL 是http://localhost/basic-2/index.php地址。所以我想从 URL 中删除(或隐藏)web子文件夹。

我在这里看到了很多解决方案...但没有什么:(,现在我有这个:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/web/$1 -f [NC]
RewriteRule ^([^/]+)$ /web/$1 [P,L,QSA]

但这只是列出文件夹和文件...并且不重定向到子文件夹。

这可以重定向,但不会从 URL 中隐藏web文件夹。

RewriteEngine On
RewriteRule ^$ web [L]

编辑1我发现了另一个规则:

RewriteEngine On
RewriteRule ^$ web/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ web/$1

这可以重定向!但是此规则仍然不会隐藏(或删除)web文件夹...

尝试类似操作:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /basic-2/
RewriteCond %{DOCUMENT_ROOT}/basic-2/web/$1 -f [NC]
RewriteRule ^(.*)$ web/$1 [P,L,QSA]
RewriteCond %{THE_REQUEST} ' /basic-2/web/([^'?' ]*)
RewriteRule ^ /basic-2/%1 [L,R=301]