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

 

 


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *