March 04, 2006



Suppose you change the name of a file. But instead of deleting the old file that is on your server (that may have many sites already linked to it) you want to forward anyone who goes to the old file URL to the new one. There are three basic ways to do this - with PHP, htaccess, or a Meta Refresh tag.

If you have php enabled on your site and server, you can use the following code to redirect a visitor to a new page:

Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location:" );

You cannot do this method from within the Movable Type editing window. Download the file from your server using FTP software. Using a text editor (such as BBEdit for the Mac or Notepad for the PC), place the code at the very top of your page. Use FTP software to upload the file back up to your server.

Another way to redirect a page is by using htaccess (for Apache servers). First, see the LMT tutorial, What is .htaccess?.

If you only want to redirect one page using htaccess, use the following:

redirect 301 /directory/oldfile.html

If you need to redirect a whole website or subdirectory of a website to a new domain, htaccess is the most convenient way to do it. To redirect all the pages in one domain to another, create a .htaccess file in your root directory (or add the following line to an htaccess file that already exists), and add the following line:

Redirect permanent /

The first "/" indicates that everything from the top level of the site down should be redirected. As long as you are using the same paths and filenames, then this is a simple way to redirect a site in the situation where you have only changed your domain name.

You can also use htaccess to redirect all the contents of a subdirectory into a new domain (assuming they have the same file paths in the new domain). I recently did this with Learning Movable Type. The site had all been under and I wanted to move it to Here is the htaccess code I have on the root directory of

redirect permanent /mt

All files that are under the mt directory are automatically redirected to

Meta Refresh Tags
One way to do a redirect is to place a Meta Refresh tag in the html header section of the file that you want to forward. The tag looks like this:

<meta http-equiv="refresh" content="3;url=">

content="3 means that when someone goes to the old file, it will take 3 seconds to be forwarded to the new file. You can change this number to be more or fewer seconds, down to zero. Note that if you use zero, it makes it difficult for the site visitor to use the back button on her browser once she is on the new page. I typically use 1 or 2 seconds.

Note that because of the back button issue the W3C does not recommend using refresh tags for redirects and suggests server side methods instead. Also, because this method has been abused by sites trying to scam search engines, search engines do not look kindly on this method.

Has this tutorial been helpful? Please consider linking to Learning Movable Type at . Thanks!

Posted by Elise Bauer on March 04, 2006 to HTML and Javascript
Comments(1) | Email to a friend | Printer-friendly version


If you would like to send a trackback
please use the following URL:


Actually, you can use PHP (or whatever) in your Movable Type editing windows, it's just a little trickier.

In my case, I have an extra blog that I use for 'system' functions such as this. If I have the need to redirect a file - typically if I screw up a title or something (which I use to create my permalink), and want to correct it.

What I'll do is create an entry in that 'system' blog with the incorrect title, and the body contains the redirect information to the correct place. That way it all stays within MT and I don't need to use FTP at all. Makes backup as easy as backing up the database, too.

The only thing this takes is an extra MT blog (be careful of paths!), and templates that use a naming system that take whatever data you want to use to place something in the 'old' location - in my case I use the same system as I use for the 'live' blog, but you can use whatever you like.

By using this method, when I 'fix' the original entry, the 'error' entry goes away, and the information I put here in this 'system' entry takes over, and sends all requests for the incorrect location to the right place.

Incidentally, I maintain my .htaccess file through MT, too. :)

Post a comment

(Before posting a comment please see the Comments and Trackbacks Policy. Do you need help troubleshooting your weblog? Please post questions and requests for support at the MT Support Forums. Thanks!)

Remember Me?

(you may use HTML tags for style)

Email to a friend

Email this article to:

Your email address:

Message (optional):