Replace directory using mod_rewrite redirect in .htaccess

Apache

Following rule will replace old-directory with new-directory in your website's URL. Add this to .htaccess file.

 
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^old-directory(.*)$ http://www.yourdomain.com/new-directory$1 [l,r=301,nc]
 

Syntax:

rewriterule - defines rewrite rule
^ - start matching
(.*) - match and remember everything
$ - end matching
$1 - append original URL part captured in (.*)
l - last rule (only omit in linked rules)
r=301 - redirect using 301 response (permanent redirect)
[nc] - non case sensitive

Newsletter

Subscribe to receive occasional updates on new posts.
Your email will not be used for any other purpose and you can unsubscribe at any time.
Please wait