.htaccess:如何在URL中删除子文件夹的子文件夹?
问题描述:
我正在尝试将此URL www.domain.com/~username
重定向到www.domain.com/~username/public
,但从URL中删除/public
.
I'm trying to redirect this URL www.domain.com/~username
to www.domain.com/~username/public
but remove the /public
from the URL.
这是我的.htaccess
文件
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /~username/
RewriteRule !^public/ public%{REQUEST_URI} [L]
RewriteCond %{THE_REQUEST} ^GET\ /public/
RewriteRule ^public/(.*) /$1 [L,R=301]
</IfModule>
但是我遇到了这个错误:
But I'm getting this error:
Not Found
The requested URL /~username/public/~username/ was not found on this server.
任何帮助表示赞赏!
答
您可以尝试以下代码:
RewriteEngine on
RewriteBase /~username/
RewriteCond %{THE_REQUEST} ^GET\ /public/ [NC]
RewriteRule ^public/(.*)$ $1 [L,R=301,NE]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]