Sammy7
Sammy7

Reputation: 372

Create a url that will ignore the first directory

I have a link www.example.com and www.example.com/user/username how can I redirect it so that when someone accesses www.example.com/username they get the same thing as if they used user?

So these links would be the same pages:

www.example.com/user/username/profile-> www.example.com/username/profile

www.example.com/user/username/messages -> www.example.com/username/messages

www.example.com/user/username/chats -> www.example.com/username/chats

Is there something I can change in .htaccess to achieve this result?

Upvotes: 2

Views: 38

Answers (1)

anubhava
anubhava

Reputation: 785481

You can use this rule in your site root .htaccess:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?!user/).+$ user/$0 [L,NC]

Upvotes: 1

Related Questions