how to remove folder name from url using htaccess

I want to change the URL from:

http://example.com/Portfolios/iPhone/app

To:

http://example.com/iPhone/app

And same for all URLs like:

example.com/Portfolios/iPad/app

To:

example.com/iPad/app

And from:

example.com/Portfolios/xyz/app

To:

example.com/xyz/app

I have tried a lot but nothing is working for me.


<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule ^Portfolios(/.*|)$ $1 [L,NC]  
</IfModule>

Solution 1:

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^Portfolios/(.*)$ /$1 [L,NC,R]

Explanation: Above rule is matching URL pattern that starts with Portfolios and have somthing like /Portfolios/xyz/app and puts xyz/app in $1. It makes an external redirection to /$1 i.e. /xyz/app.

These are the flags used:

L  - Last
NC - Ignore (No) Case comparison
R  - External redirection (with 302) -- can be changed to R=301