Redirect a page to another domain/page
tonyn | July 21, 2009HTML
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>
<html>
<head>
<title>Your Page Title</title>
<meta http-equiv=”REFRESH” content=”0;url=http://www.the-domain-you-want-to-redirect-to.com/the-page.html”></HEAD>
<BODY>
Optional page text here.
</BODY>
</HTML>
After 5 seconds, redirect to another page
<meta http-equiv=”Refresh” content=”5; url=http://www.new-domain-name-or-old-domain-name.com/html/tags.jsp”>
JavaScript
<script language=”Javascript” type=”text/javascript”> <!– Hide script //<![CDATA[ window.location.href="http://www.unix86.org.com/" //]]> End script hiding –> </script>
PHP redirect (index.php)
<?php header(”Location: http://www.unix86.com/”); ?>
Perl Redirect
#!/usr/bin/perl -w use strict; use CGI qw/:standard/; print redirect(’http://www.ibm.com’);
More efficient, not loading the CGI module:
#!/usr/bin/perl -w use strict; print ‘Status: 302 Moved’, “\r\n”, ‘Location: http://www.ibm.com’, “\r\n\r\n”;
Apache redirect
Apache redirects are recommended if you want to redirect all web pages in a directory to a new place.
In httpd.conf:
Redirect /mydirectory to http://www.unix86.com/personal
For example, accessing http://www.unix86.com/mydirectory/photos.html will redirect the browser to http://www.unix86.com/personal/photos.html
The following example redirects any page (even non-existing ones) to a new site:
RedirectMatch (.*) http://www.unix86.com
This example makes the browser to load the web page from this server, but using another server to load the images
RedirectMatch (.*)\.png$ http://www.unix86.com/images/$1.png
RedirectMatch (.*)\.jpg$ http://www.unix86.com/images/$1.jpg
RedirectMatch (.*)\.jpeg$ http://www.unix86.com/images/$1.jpeg
RedirectMatch (.*)\.gif$ http://www.unix86.com/images/$1.gif