I saw nintendo's thread at the top but didn't work for me. Also if someone sets the ?setID to =anything - then no content is on the page, but the shows missing content that should be there - so I'd want it replaced with a blank page or redirect. Sorry guys for being so lame...
Use these directives to rewrite "/page/$NAME/" into "/page.php?setID=$NAME": RewriteEngine On RewriteBase / RewriteRule ^page/([^/]+)/$ /page.php?setID=$1 [L] Code (markup):
Rather than trying to make .htaccess turn the URI into getdata, I simply use a whitelist of files I want to have normal access, then redirect ALL requests to a single index.php thus: # redirect all 'unknown' requests to index.php RewriteEngine On RewriteRule !\.(gif|jpg|png|css|js|html|htm|txt|ico|zip|gz|rar|pdf|xml|wav|mp3|mp4|mpg|flv|swf|mkv|ogg|avi|webm|woff|svg|eot|ttf)$ index.php Code (markup): Then I just parse $_SERVER['REQUEST_URI'] to extract the path. I have a singleton all nice and ready to handle that: final class request { private static $data = []; public static function value($index = 0) { if (count(self::$data) == 0) { if (strpos( $url = str_replace(['\\','%5C','/',$_SERVER['REQUEST_URI']), '../' )) die('Hacking Attempt Detected'); $offset = strlen($_SERVER['PHP_SELF'])-9; if ($end = strpos($url,'?')) { $end -= $offset; } else $end = 4096; $url = str_replace('\\','/',substr($url,$offset,$end)); self::$data = empty($url) ? ['default'] : explode('/',$url); } return isset(self::$data[$index]) ? self::$data[$index] : false; } } // request Code (markup): Default is index 0, so for example if your URI was your.url/ request::value() == 'default' request::value(1) == false if your URI was your.url/test/goomba request::value() == 'test' request::value(0) == 'test' request::value(1) == 'goomba' request::value(2) == false This method also preserves getdata,so you could pass your.url/test?whiskey=tangoFoxtrot for the following results: request::value() == 'test' request::value(1) == false $_GET['whiskey'] == 'tangoFoxtrot' Comes out quite reliable and easy to use. Some people balk at making a large whitelist like that, but I really prefer it to trying to shove that information into getData, particularly since all the other methods erase any existing getData.
Thanks guys. Esp to Deathshadow but I've got 200+ files to add to the "$_GET['whiskey'] ==" request, so might be a bit complex. On the idea of ?setID=NotaPage, is there some PHP I could use to just show nothing ifs someone is questing a page with nothing on i.e.: if ($_GET["setID"] == (True?) - i.e. the exact thing in the DB then show content else - show nothing...
I think you missed how it works -- I said you can use $_GET in ADDITION to paths... You wouldn't pass them that way for simple 'files' / pages. If you had /page/name, my routine would return: request::value() == 'page' request::value(1) == 'name' So you could do: if (request::value() == 'page') { if ($target = request::value(1)) { if ($target != preg_replace('/[^\w]/', '', $target)) { die('Invalid characters in page name.'); } else if (fileExists($target = 'pages/'.$target.'.page.php')) { // might be good place to call template headers require_once($target); // might be good place to call template footers } } else { die('no page specified'); } } Code (markup): That way "/page/test" will try to run "/pages/test.page.php", "/page/jimbo" would run "/pages/jimbo.page.php", etc, etc... You don't use get for simply loading pages at all. My method just lets you still pass getData should you want it for things like searches. (where it's nice to show the search term in the URI).