Forum Moderators: coopster
Set:
ErrorDocument 404 /path/to/phpfile.php
In your .htaccess file
That will direct any request for a URL which doesn't exist to your script.
In your script, read $_SERVER[REQUEST_URI] (typed address in browser), and decide what to do with it.
If you want to give out something, be sure to send, using header(), a 200 OK status to override the default 404 Not Found status.
the wordpress is using apache mod rewrite to follow that URLs scheme but it is not necessary you also implement it with apache mod rewrite. you can find a PURE PHP solution too to implement the same modRewrite kinda URLs scheme. You just need to have a clear-cut logic of fetching URLs and then fetching data from database based on different values.
there is a very good post on doing this with pure php on zend official site but i cannot give you URL because its against the forum URL policy...
The following code is used in OSCommerce for "Search Engine Friendly" pages:
if (strlen(getenv('PATH_INFO')) > 1) {
$GET_array = array();
$PHP_SELF = str_replace(getenv('PATH_INFO'), '', $PHP_SELF);
$vars = explode('/', substr(getenv('PATH_INFO'), 1));
for ($i=0, $n=sizeof($vars); $i<$n; $i++) {
if (strpos($vars[$i], '[]')) {
$GET_array[substr($vars[$i], 0, -2)][] = $vars[$i+1];
} else {
$HTTP_GET_VARS[$vars[$i]] = $vars[$i+1];
}
$i++;
}if (sizeof($GET_array) > 0) {
while (list($key, $value) = each($GET_array)) {
$HTTP_GET_VARS[$key] = $value;
}
}
}
This takes the URL and converts it into key/value pairs, and then defines $HTTP_GET_VARS['key'] as the value. You can then check for the corresponding $HTTP_GET_VARS in your code.
As in any case when accepting input from "the outside" and including it in your code, proper validation of the input is required for script integrity.
Hope this helps,
SK