问题
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