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$ http://newsite.com/page.html [R=301,L]

With Mod_Alias:
Redirect 301 /page.html http://newsite.com/page.html

JSP/Java 301 Redirect
response.setStatus(301);
response.setHeader( "Location", "http://newsite.com/page.html" );
response.setHeader( "Connection", "close" );

PHP 301 Redirect
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://newsite.com/page.html");
exit();

Node.JS 301 Redirect
var http = require("http");
http.createServer(function (req, res) {
res.writeHead(301, {"Location": "http://newsite.com/page.html"});
res.end();
}).listen(8080);

ASP 301 Redirect
<%
Response.Status="301 Moved Permanently"
Response.AddHeader='Location','http://newsite.com/page.html'
%>

CGI PERL 301 Redirect
use CGI;
my $q = CGI->new();
print $q->redirect(
-location => 'http://newsite.com/page.html',
-status => 301,
);

Coldfusion 301 Redirect
<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="http://newsite.com/page.html">

Python (with Django) 301 Redirect
from django import http
def view(request):
return http.HttpResponsePermanentRedirect ('http://newsite.com/page.html')

ROR (Ruby on Rails) 301 Redirect
def old_action
headers["Status"] = "301 Moved Permanently"
redirect_to "http://www.domain.com/"
end

Stay up to date

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

Loading...

MORE
INSIGHT

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.

GET
CLARITY

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.

Loading...