301 htaccess redirect

Written by
Date: 2012-12-23 17:44:32 00:00

I am moving some posts from an old site to a new one, and because now I am using Apache as my web server (for some time at least). I am using .htaccess file to redirect old url to new ones with a 301 (permanent) http code.

Using Apache's .htaccess 301 redirect is one of the most efficient way to redirect old URI to new URI.

Edit the .htaccess file (should be in your root public folder). I use vim, you can use your favorite.

Enter this lines in .htaccess file:

Redirect 301 /page1.html http://new.site.com/new-page.html
Redirect 301 /old-path http://new.site.com/new-path.html
Redirect 301 /some-file.jpg http://new.site.com/some-file.jpg

It is that easy, just enter as many lines as you need.

If you want to redirect a complete site to a new domain, with all internal URLs intact, just enter this single line in the old domain .htaccess file.

Redirect 301 / http://www.example.com/