how to remove folder name from url using htaccess how to remove folder name from url using htaccess apache apache

how to remove folder name from url using htaccess


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 onRewriteEngine OnRewriteBase /RewriteRule ^Portfolios/(.*)$ /$1 [L,NC,R]

Explanation: Above rules is matching URL patter 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  - LastNC - Ignore (No) Case comparisonR  - External redirection (with 302) -- can be changed to R=301


You can also set your root directory as /var/www/Portfolios instead of /var/www/ in /etc/apache2/sites-enabled by writing DocumentRoot line as

DocumentRoot /var/www/Portfolios

instead of DocumentRoot /var/www/and also this line< Directory /var/www/ > changed to

< Directory /var/www/Portfolios/ >