Creating 301 Redirects

Because of popular demand from the forum, this is a tutorial on creating a 301 redirect. For those of you who don’t know, a 301 redirect is a way redirect visitors to another page and to tell search engines that the content is permanently moved. A 301 redirect is the most search engine friendly redirect because it will pass the most authority from the old page to the new page. For this tutorial we’ll assume that your website is on a Linux server (for the htaccess example).

PHP 301 Redirect – The PHP 301 redirect is popular because it’s an easy way to move a single page. Simple create a PHP file and paste this code into it for the redirect

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://example.com/newpage");
?>

htaccess 301 Redirect – 301 redirects through a directory htaccess file are also popular because this allows you to redirect all the pages in entire directories without having to go through each file. You would use an htaccess redirect if you change domains or your URL structure.  (There is no reason to use an htaccess redirect for a single file). Paste this code into your htaccess file for a directory-wide redirect

Redirect 301 / https://example.com/new/

You can also use htaccess redirects to redirect all WWW pages to non-WWW or all non-WWW pages to WWW if you have a preference. I recommend you pick one and stick to it.

Techie

I am Techie, the webmaster and main author for the w3techie blog.

You may also like...

7 Responses

  1. I thought it was worth mentioning that those using the WordPress content management system can use a plugin to add 301 redirects – the best of which is probably 'redirections'. Just to save WordPress users the trouble of finding and editing the htaccess file.

    Great post though, really useful information. Thanks for taking the time to post

  2. Techie says:

    Are you talking about cPanel and similar or more software-specific like WordPress plugins and forum plugins?

  3. Techie says:

    Of course not. That's like saying "If I link to Google will my site be more trusted?" Voting for a site with a link doesn't bring anything to your site.

  4. Medora says:

    That simple .htaccess method did the trick for me. Unfortunately, I still need to figure out how to get URLs for particular topics from the old domain to reroute to the new one. I suppose the problem may be that my forum is under the root directory for the new domain, but for the old one it was under /forum/.

  5. Jake says:

    Thanks for clearing this up. A lot of people talk about new domain names instantly receiving high rankings, for example when two businesses join to create a new business under a new domain name. Usually, it's 301 Redirects that cause the instant high rankings.

  6. Kevin says:

    Useful info as I see so many sites that don't use a 301 redirect on different versions of the home page URL and all sites should have it otherwise search ranking could be affected. If you try with and without the www. on a website most won't have the 301 redirect on.

Leave a Reply to Techie Cancel reply

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