Skip To Main ContentClarity Global

Single page 301 redirects on different platforms

A 301 redirect is the search friendly method of advising search engines where they can discover the new location for the current URL. When moving/removing content with backlinks a 301 is strongly recommended to maintain backlink equity, this will ensure any search rankings and backlinks a webpage previously gained are retained on the new webpage.

The code examples below show how to perform this 301 redirect from one URL to another across various common web platforms/languages.

Apache 301 Redirect
With Mod_Rewrite:
RewriteRule ^page.html$ [R=301,L]

With Mod_Alias:
Redirect 301 /page.html

JSP/Java 301 Redirect
response.setHeader( "Location", "" );
response.setHeader( "Connection", "close" );

PHP 301 Redirect
header("HTTP/1.1 301 Moved Permanently");

Node.JS 301 Redirect
var http = require("http");
http.createServer(function (req, res) {
res.writeHead(301, {"Location": ""});

ASP 301 Redirect
Response.Status="301 Moved Permanently"

CGI PERL 301 Redirect
use CGI;
my $q = CGI->new();
print $q->redirect(
-location => '',
-status => 301,

Coldfusion 301 Redirect
<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="">

Python (with Django) 301 Redirect
from django import http
def view(request):
return http.HttpResponsePermanentRedirect ('')

ROR (Ruby on Rails) 301 Redirect
def old_action
headers["Status"] = "301 Moved Permanently"
redirect_to ""

Stay up to date

Receive all the latest news, events, and insights on B2B tech, marketing, and communications with Clarity’s free monthly newsletter.



Fearless tactics to achieve your strategic success

As a consultancy, our full-funnel marketing and communications solutions are designed to fearlessly deliver business results across multiple industries and service areas.


Looking for a partner to help you reach your goals? We’d love to hear from you.

As a global full service agency, our services reach far and wide. Wondering what type of projects we take on, alongside budgets and timelines? Find more information on our Service and Sector pages.