The most common mistake I see in php scripts is directory paths. Most
people don't understand how to reach directories above the current
location or get back to index without using the index file name. The
following code provides a variable with a link to the index file.
$uriCount = explode("/", $_SERVER[REQUEST_URI]);
$selfCount = explode("/", $_SERVER[PHP_SELF]);
$depth = count($uriCount) - count($selfCount);
$dirRoot = "";
while ($depth) {
$dirRoot .= "../";
$depth--;
}
By using the difference between the uri slash count and the self slash
count you end up with the depth of the current rewrite directory. This
only works for a site with a .htaccess path translator but conveys a
simple process to handle directories. A double dot followed by a slash
is repeated that many times going a directory higher each time. Follows
is an example of .htaccess
RewriteEngine On
RewriteRule ^app/([A-Za-z0-9_-]+)$ index.php?app=$1 [L]
This will translate http://www.yoursite.com/app/test into
http://www.yoursite.com/index.php?app=test. The user never sees that all
directories are processed by a single index.php.