Owen Kavanagh Owen Kavanagh - 1 year ago 77
Apache Configuration Question

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

I'm trying to redirect this URL

but remove the
from the URL.

This is my

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


But I'm getting this error:

Not Found

The requested URL /~username/public/~username/ was not found on this server.

Any help appreciated!

Answer Source

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]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download