Home > Projects > Redirect Page
I occasionally need to create a page that redirects to another page, e.g, when a site is moved. Three versions are provided here:
- A JSP page that sends a 301 status code indicating a permanent move.
- A PHP page that sends a 301 status code.
- A plain HTML page using the meta refresh tag.
JSP Page
<%
response.setStatus(301);
response.setHeader("Location", "http://www.newurl.com");
%>
PHP Page
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newurl.com");
exit();
?>
Meta Refresh Tag
<html>
<head>
<title>Page Moved</title>
<meta http-equiv="Refresh"
content="0; url=http://www.newurl.com">
</head>
<body>
<h1>Page Moved</h1>
<p>This page has been moved to <a href="http://www.newurl.com">
http://www.newurl.com</a>.</p>
</body>
</html>