301 Redirect Codes For PHP, ASP, Coldfusion, and More

Posted 1950 days ago - Development

301 is an HTTP status code that basically instructs search engines and browsers that a page has moved, permanently. If you've changed a file name, domain, folder path, whatever, a 301 redirect will update the search engines. This ensures your content remains indexed and available via search engines.

PHP 301 Redirect Code

<?php Header( "HTTP/1.1 301 Moved Permanently" ); Header( "Location: http://www.new-url-here.com" ); ?>

ASP 301 Redirect Code

<%@ Language=VBScript %> <% Response.Status="301 Moved Permanently"; Response.AddHeader("Location","http://www.new-url-here.com/"); %>

ASP.net 301 Redirect Code

<script runat="server"%> private void Page_Load(object sender, System.EventArgs e) { Response.Status = "301 Moved Permanently"; Response.AddHeader("Location","http://www.new-url-here.com"); } </script>

Coldfusion 301 Redirect Code

<cfheader statuscode="301" statustext="Moved permanently"> <cfheader name="Location" value="http://www.new-url-here.com">

Perl 301 Redirect Code

#!/usr/bin/perl -w use strict; print "Status: 301 Moved Permanantly\n"; print "Location: http://www.new-url-here.com/page.htm\n\n"; exit;

In addition, javascript, meta refresh tags, and some web-servers even support redirection management via conf files. If there's a particular redirect you'd like to know more about but can't seem to find any information, post a comment and I'll do my best to provide some guidance.

Word Count: 241

Tags: , , , , ,

Click Here to Submit a Comment

Permalink / Last Modified:

Support Nullamatix.com:

See Also:

  • 04/11/2010 -- Howto: XCache in a Lighttpd Chroot on Debian
    Excerpt: "Whether you're pressed for resources on a virtual/dedicated server, or simply looking for ways to improve web application performance, XCache is guaranteed to produce the desired result. Within minutes of installing XCache: page load times were cut in half, ..."
  • 01/17/2010 -- New Tool: IP Range to CIDR
    Excerpt: "At least twice a week I find myself visiting ip2cidr.com, the IP to CIDR converter. Since the owner/author of the site hasn't release the source code, and I love a challenge, I developed my own version. The guys at the job find the tool useful, and after a ..."
  • 12/26/2009 -- WordPress Hacks Worth Implementing
    Excerpt: "Combat Comment Spam Most spammers aren't clever enough to populate the REFERER header. This code snippet is not only extremely easy to implement, but pretty effective, too. Open up your themes functions.php and drop in the following: function ..."
  • 12/10/2009 -- 529 Attacks in 9 Days: id1.txt, RFI, & More
    Excerpt: "Long time Nullamatix readers know how much I love reviewing log files. Logs can provide detailed incite into not only the overall health of a system, but information one can use to mitigate the risks of automated attacks. In this post, I'll go over a couple ..."

Leave a Reply