One of the first things many Apache administrators end up with in their bag of tricks is a piece of code for redirecting a website to another place. 301 redirects are usually better, but a basic redirection page is also very helpful in a number of situations. The following example code can be saved as an index.html page and will redirect traffic from one site to another. A common use of this is to redirect an http site to an https site. In this example, we’ll place this index page in the web directory for https://krypted.com/ on an OS X Lion server. The server runs a site for https://krypted.com/ already and so this page is simply meant to redirect users to the https version of the site:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>krypted.com Secure Redirect</title>
<meta http-equiv="REFRESH" content="0;url=https://krypted.com/">
</HEAD>
<BODY>
You will now be redirected to https://krypted.com/
</BODY>
</HTML>
Above, we create an HTML tag, a heading tag, a title tag and finally the meta http-equiv refresh. The content used between the body tag is simply to inform a user who might happen to see this site what is happening. Simply copy this into an html file and you’re off to the races. If using OS X Server, you can drop into /Library/WebServer/Documents by default, to redirect users elsewhere.