Quick Redirect Page
When I install PHP software in it's own directory, I generally also provide an index.php
file. Unless it's needed for something else, the index file redirects to the PHP software.
To get to the newly-installed PHP software, then, requires me to only remember the directory name. The index page redirects the browser to the script it should run.
The entire index.php
file generally consists of this line.
<?php header("Location:./dashboard.php") ?>
For your implementation, replace ./dashboard.php
with the URL of the browser's destination, the URL where you want the browser to be redirected to.
The above is the fastest redirect available for web pages because PHP is processed and acted on before any content is sent to the browser.
For non-PHP web pages, JavaScript can be used.
<script>location.href="./dashboard.php"</script>
Replace ./dashboard.php
with the URL of the browser's destination.
For JavaScript, the web page is sent to the browser. When the browser enconters the JavaScript, it redirects the page. Therefore, the higher on the page that the browser finds the JavaScript, the sooner the redirect occurs.
Another method avaialble for non-PHP web pages is the meta redirect.
<meta http-equiv="refresh" content="0; url=./dashboard.php">
As with the others, replace ./dashboard.php
with the URL of the browser's destination.
Place the meta tag in the head
area of the web page. The redirect should occur within a second of the browser encountering the meta tag.
The methods described here can be used for other redirect needs, too.
For the JavaScript and meta tag redirect methods, consider that some browsers or firewalls can be set up to block redirects.
Therefore, if you can, use the PHP redirect method. The PHP redirect method occurs on the server, before any content gets to the browser and any browser redirect blocking can occur.
Related articles are:
-
Ways to Redirect Bots and Browsers includes a description of the
.htaccess
file method of redirecting. -
PHP Redirect That Works to ensure the redirect is effective even when headers have already been sent in PHP scripts.
-
Redirect Browsers, Not Bots for when you really don't want bots at the browser destination.
(This content first appeared in Possibilities newsletter.)
Will Bontrager