If you move to a new host and your URLs change, you can loose traffic. You can put links to the new pages or use javascript to redrect but PHP has a better way.
<?
header("HTTP/1.1 301 Moved Permanently");
header("Location: $url");
exit();
?>
This has to be at the top of the page before any HTML and if you do have HTML, it won't be seen unless you have some if statement that describes some condition under which the redirect script won't be enabled. Otherwise, browsers will be redirected before anything else is read. If you use a variable instead of a URL, you can use a form to input it. Create a .php page named redirect.php with this code
<?
$url = $_REQUEST[url];
if ( isset() )
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: $url");
exit();
}
?>
You can then use a drop menu one any other or your pages or your email sig to submit the URL like this:
<form action="http://YourSite.com/redirect.php">
<select name="url">
<option value="Link URL">Link Name</option>
<option value="Link URL">Link Name</option>
<option value="Link URL">Link Name</option>
</select>
<input type="submit" />
</form>
If you are using a drop menu for navigation on a web site, you can make it so javascript powers it and if webtv's javascript bug bites, PHP takes over. First put this code on the head:
<script language="javascript">
function formhandler(form)
{ var url = form.site.options[form.site.selectedIndex].value;
window.location.href = url; }
</script>
Since you don't need the submit button for the javascipt redirector to work, hide it with <noframes<. When javascript is working, you don't see the button. When javascript is disabled, the button is there to use the PHP redirector.
<form name="form">
<select name="url" onchange="formhandler(this.form)">
<option value="Link URL">Link Name</option>
<option value="Link URL">Link Name</option>
<option value="Link URL">Link Name</option>
</select>
<noframes>
<input type="submit" value="Go">
</noframes>
</form>
|
|
|