Andy Crawford | Reborn in PHP

Index Page

Published January 2022 | By Andy Crawford

What is an 'Index' page

Source Code Image

An index page is the content which automatically loads when a domain is called for by a web browser.

In this case, any request for andycrawford.net will open andycrawford.net/index.php, as index.php (or index.html) is the standard server default. The code contained inside index.php on this website is as follows: (Note: See foot of page)

<?php
header("Location: pages/index");
exit();
?>

This php code above redirects the user to the folder andycrawford.net/pages/index Inside that folder is the file index.php which is where you are at now.

The reason I have done this is so that every page is contained within its own sub-folder and that only 'the domain' and 'sub-folders' need to be called in the URL (eg. andycrawford.net/pages/page-name). to call a page

This also applies to the 'index' page as well ../pages/index/index.php. The top level 'index.php' file redirects to the 'pages/index subfolder' and inside the 'pages/index sub folder' there is another 'index.php' file that contains the following code that loads the page:

<?php echo file_get_contents("../../includes/php/meta.php"); ?>
<title>Index Page</title>
<meta name="description" content="What is an 'Index' page.">
<?php echo file_get_contents("../../includes/php/body-header.php"); ?>
<?php echo file_get_contents("body-content.php"); ?>
<?php echo file_get_contents("../../includes/php/no-body-footer.php"); ?>
<?php include "../../includes/php/body-copyright.php" ?>
<?php echo file_get_contents("../../includes/php/close.php"); ?>

This Code Returns:

The standard html (meta.php, body-header.php, (no)body-footer.php and close.html).
The page specific html (body-content.html).
Plus some customisable meta data (title, description) and a copright notice.

To Change the Index Page

If I want to change the Index page at any time, all I need to do is to go to the original index.php file and change "Location: index" to "Location: name-of-page-folder-to-be-index-page". I might do this at some point as an index page about the index page is pretty boring really.

I did it!

I changed the index.php to redirect to "/pages/menu-page-site-map". I am sure you will agree that it is a lot more useful than this page.