Redirecting and Duplicating Content Properly

There are certainly times when all Web developers and “information architects” find themselves in a situation where they need to move content from one page to another. When you do so, you need to redirect visitors from the old location to the new location, and you need to do so properly. To do that, you need to make sure that the old location returns the correct status code (301 – Moved Permanently). There are a number of ways to do this. The most efficient way, for apache users, is to set up a redirect inside of your .htaccess file. However, if you don’t have permission to set up redirects within .htaccess, you can use PHP (or any other server-side scripting language) to do so. Using meta refresh tags and javascript is not generally the best way to redirect your visitors.

To use .htaccess, you will need to have the apache rewrite module installed and configured, and you will need a decent understanding of how the rewrite module works. Unfortunately, that’s a bit too complex to get into in this simple tutorial. However, there is a lot of great information on the Web already about using apache rewrite to redirect visitors.

To use PHP, you simply use the “header” function to alter the header of the page. In using the “header” function, though, you need to make sure that no other content has been printed, yet (not even a blank space or carriage return). You can then use code similar to the following:

header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$newlocation);

When you use the header function to redirect users with PHP, you need to make sure you call die() to kill the script. PHP continues to run until the script runs out or it encounters a die() command, so it’s possible that the PHP script will perform unintended actions if you don’t use die() to kill the script immediately after the header call. Also, you have to call two separate header functions to redirect properly (one to send the status code, the second to send the new location). If you try to insert a new line in the header command, it will throw an error.

WebConfs has a good article explaining quite a few different methods for redirecting. The bottom line is, however, that you must make sure to send the 301 status code.

There are also situations when it makes sense to duplicate content on multiple pages. For instance, in the field of higher education, it makes perfect sense that some information will apply both to current students and prospective students. To keep your navigation structure in tact, though, it might not make sense just to point both types of visitors to the same page. Instead, it makes more sense to create duplicate pages and place each under the appropriate level in the architecture of the site. However, if you simply duplicate the content, search engines will begin to punish you for doing so.

To inform the search engines that the duplicated content is intentional (and to tell them which version should be indexed), you need to use the canonical meta tag. The canonical meta tag is basically just a way to tell the search engines that the content on this page is a duplicate of another page, and then points the search engines toward the original page.

Assuming that your original content is found on a page called “original-page”, you would use a tag similar to the following if you duplicated that content on “duplicate-page” (the canonical tag goes inside of the head section of duplicate-page):

<link rel="canonical" href="" />

One Response