.htaccess:如何在URL中删除子文件夹的子文件夹? [英] .htaccess: How to remove subfolder's subfolder in URL?
本文介绍了.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]
这篇关于.htaccess:如何在URL中删除子文件夹的子文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文