Primary Nav

301 Redirect with htaccess

There are several WordPress plugins that will do redirects (redirecting one URL to a different URL), but the simplest and sometimes least burden on the system resources is by using the .htaccess file. It’s technical (meaning you have to edit a file), but it’s simple and it just works. It’s also fast as the browser reads the .htaccess file first, so it doesn’t take the time of a meta tag or some other refresh or reload.

You will need access to the server files. If that already scares you, you might want to stop right there as the htaccess file is a powerful file. One blank space or incorrect bracket and your site might stop working. Yes, if you go fix the bracket, it will be up again, but just so you know: you’ve been warned!

Here’s the simplest code that you put in your .htaccess file that redirects one old URL to a new URL:

Redirect 301 /oldpage.html http://www.newsite.com/newpage.html
Redirect 301 /oldpage2.html http://www.newsite.com/newpage2/
Redirect 301 /oldpage3/ http://www.newsite.com/newpage3/

As you can see, you can redirect an HTML page to another HTML page or an HTML page to a new non-HTML (e.g. PHP or ASP) page. It’s a simple command: if a visitor hits this old URL, take them to this new URL.

This code will redirect your entire site to another URL. The slash ” / ” in there denotes the entire site, not just a page, post or directory.

Redirect / http://newsite.com/

You put the .htaccess file in the root directory of the old site, which is why we don’t need to say what the old URL is (e.g. http://oldsite.com).

One Response to 301 Redirect with htaccess

  1. tim March 30, 2013 at 9:58 am #

    This is cool. I am one of the ones that htaccess makes nervous. This is nugget is going in my snips file.

Leave a Reply