kdmurray.blog

The crossroads of life and tech

Redirecting Your Website (URL Redirection)

It’s late, and I’m tired, so this is gonna be a short post.  I got a question from @Mattoid12 on twitter tonight about how to redirect a website.  I’m going to show three ways, and then provide a link to a site which shows every conceivable way of redirecting a website.

.htaccess File

If you have access to edit your .htaccess file (FTP or SSH access to your server) put this line at the top.  It will redirect the local url “/” (root) to the new location.  More on HTTP 301 here.  I’ve discussed this in more detail on a previous post.

Redirect 301 / http://yournewwebsite.net/

HTML Meta Tag

The example below will redirect a page to the new location after two seconds.  This code should be placed at the top of your index or default page.

<meta http-equiv="refresh" content="2;url=http://yournewwebsite.net">

PHP Redirect

This method is sort of a combination of the above two approaches.  It will perform an instant redirect and return HTTP 301 to the browser.  This code needs to be entered in your index.php file.

<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://yournewwebsite.net" );
?>

For examples of a large number of other possible redirects are available on webconfs.com.