Single page 301 redirects on different platforms

William Julian-Vicary

Strategy & Innovation Director

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

Related Posts

Inside Screaming Frog: Top Takeaways From The Workshop

Ensuring that your URLs can be crawled and indexed is a cornerstone of SEO. If Google can’t find that lovely content you want to get in front of your customers, what’s the point in writing it, right?


1 year ago

Our top takeaways from BrightonSEO

Learn how to implement a 301 redirect from one page to another for different platforms, such as PHP, Java, Apache, ASP, CGI, Python, ColdFusion & Ruby.


2 years ago

Google changes affecting local queries

As Google continuously updates in order to keep up with our ever-changing world of tech, we ask, what are the recent changes affecting local queries?


2 years ago

Ditch the hassle: Excel secrets to master keyphrase research

Learn how to implement a 301 redirect from one page to another for different platforms, such as PHP, Java, Apache, ASP, CGI, Python, ColdFusion & Ruby.


3 years ago

How to respond to negative Google My Business reviews

Learn how to implement a 301 redirect from one page to another for different platforms, such as PHP, Java, Apache, ASP, CGI, Python, ColdFusion & Ruby.


3 years ago

Seven beginner WordPress plugins

In this article we've compiled some of the absolute best WordPress SEO plugins – and more – for making the job of optimising your website that much easier.


3 years ago

Drag