<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> Code (markup): Here is the php file <?php // first of all, quit if the server is running on PHP <5 if( phpversion() < '5.0' ){ die('Your server is running the setup with PHP v' . phpversion() . ' - you will need at least PHP 5 to use Template Blocks.'); } //de-compile the URL into variables $uri = substr( $_SERVER['REQUEST_URI'], strlen(dirname($_SERVER['PHP_SELF']) ) ); $uri_parts = parse_url($uri); $uri_path = explode('/', $uri_parts['path']); $extensions = array(".html", ".htm", ".php", "/"); // get the section, if requesting a directory (empty filename) jump one level up $section = array_pop($uri_path); if( $section == '' ){ $section = array_pop($uri_path); } // these are the two variables we actually need $GLOBALS['section'] = str_replace($extensions, '', $section); $GLOBALS['parents'] = $uri_path; // on to load our template... // CHANGE THIS IF YOU WANT THE TEMPLATE SOMEWHERE ELSE include( 'template/index.php'); ?> PHP: Can you explain it
What it does it is takes any URL that is typed into the domain starting from the directory .htaccess is placed in, and sends it all to index.php. Your index.php file then takes the url, slices it into chunks, stores the chunks into a global array, and includes the index.php file located in your templates directory. This looks like the starting point for a PHP framework or template engine. Type something in like the following before your include() line: print_r($GLOBALS['sections']); print_r($GLOBALS['parent']); exit(); PHP: Then go to www.yourdomain.com/one/two/three.htm So that you can see exactly what is happening.