I keep all my scripts, stylesheets, and php files in separate folders. Each site page has a require() statement, then includes the necessary files. As a temporary measure, I have them relative to the site root, and only one directory deep. For example:
/back/php/scripts.php:
<script src="../back/js/lighbox.js"></script>
<script src="../back/js/site.js"></script>
/home/index.php, /services/index.php, /portfolio/index.php:
<head>
<? require "../back/php/scripts.php"; ?>
</head>
/:
<? header("Location: home/"); ?>
I’m certain there is a better way to handle site structure, as this limits me to only one depth for directories, and also an extra redirect at the start. I’d appreciate your input. How should this be changed? How do you structure your site architecture?
You could use a front controller type system.
All URLs are redirected through index.php using mod_rewrite and it handles the bootstrapping of the files you need (through an autoloader mechanism preferably) along with the related routing.
This also has the added benefit of allowing you to move almost all your PHP out of the httpdocs folder.
So your file layout would be something like this: