.htaccess: How to remove subfolder's subfolder in URL?

本小妞迷上赌 提交于 2019-12-12 20:47:00

问题


I'm trying to redirect this URL www.domain.com/~username to www.domain.com/~username/public but remove the /public from the URL.

This is my .htaccess file

<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.

Any help appreciated!


回答1:


You can try this code:

RewriteEngine on
RewriteBase /~username/

RewriteCond %{THE_REQUEST} ^GET\ /public/ [NC]
RewriteRule ^public/(.*)$ $1 [L,R=301,NE]

RewriteRule ^((?!public/).*)$ public/$1 [L,NC]


来源:https://stackoverflow.com/questions/27092810/htaccess-how-to-remove-subfolders-subfolder-in-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!