Owen Kavanagh
Owen Kavanagh

Reputation: 197

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

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!

Upvotes: 2

Views: 1705

Answers (1)

anubhava
anubhava

Reputation: 784898

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]

Upvotes: 2

Related Questions