Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibraryWebsite Automation

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Redirecting with PHP

When we installed our new central Download Handler software, we wanted to direct download links from old download handlers to the new one.

Most of the old download handlers were PHP. So I simply replaced the old download handler scripts with a script containing a PHP redirect to the new software.

I'll show you how I did it. And also give you additional information about redirecting with PHP.

To redirect clicks to the new central download handler I replaced the old PHP script with:

<?php
header("Location: /DownloadHandlerLink.php?file=myfile.zip");
?>

"/DownloadHandlerLink.php" is the URL to the new Download Handler software. The URL may be relative or absolute http://... . "myfile.zip" is the name of the file being downloaded.

Links to the old download scripts at social sites and on your web pages can remain unchanged.

To avoid yet more lines in the .htaccess file, a PHP script can be replaced with code to redirect the browser to the new location.

Here is a recap of the format and additional details:

header("Location: URL");

Replace "URL" with the URL the browser is to be redirected to.

If more PHP code follows that header() command, put an exit command on the next line. It is to prevent the execution of the other PHP code. Like:

header("Location: URL");
exit;

The above format will redirect with status "302 Found", which is a temporary move status.

To redirect with status "301 Moved Permanently", use this format:

header("Location: URL", true, 301);

Replace "URL" with the URL the browser is to be redirected to.

The "true" (no quotes) parameter causes any earlier headers with the same name to be replaced with this one. The "301" (no quotes) parameter is the status code to send to the browser.

When a PHP script is moved or a different one is to be used at a different location, links to the old PHP script either need to be changed or a redirect implemented.

A redirect can be implemented without .htaccess lines by replacing the old PHP script with redirect code.

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC