Consider this workflow:
User makes a request to website.com/lolmyblogpost
My .htacces is all like…
RewriteCond %{REQUEST_URI} !=/index.php
RewriteRule .* /index.php
Where in index.php im going to search a file tree of templates for lolmyblogpost.html returning:
/path/to/lolmyblogpost.html
So in my master template I can:
{include file="{$pathToTemplate}"}
How do I search a directory tree for a file and return the file path?
What you really want is “look back” support with a default type. Set up your Apache virtual host (something) like this:
The important line is
DefaultType application/x-httpd-php, which means you can now get rid of the.phpfile extension.You can now use a URL like
http://example.com/this_is_a_php_pageand you can also usehttp://example.com/this_is_a_php_page/with_a_path_info_var.So, on
this_is_a_php_page(which is really a .php file without an extension) you can use$_SERVER['PATH_INFO']to check for and vars that are being passed in the URI.Edit:
Added the
RewriteEngineand rule to push everything toindex.php. This means you now have a (real) single page on the server calledindex.phpwhich will need to check the$_SERVER['REDIRECT_URL']var for what was really requested.For example, a request for
http://example.com/a_pagewill now loadindex.phpwitha_pagepassed to$_SERVER['REDIRECT_URL']. NOTE: this solution will push everything to index.php. You will need to include an exception like:To allow all files that start with
not_me_plzfiles to be served “as expected”.