|
Posted by Janwillem Borleffs on 11/18/65 11:41
Laeronai wrote:
> I'm making a blog cms and have been having trouble with making the
> URLs look good. Each post goes to a URL like "viewpost.php?id=40" but
> I want the URL to look like "YYYY/MM/TITLE" so it would come out to be
> "/2006/03/hey-look-its-march." Does anyone know how to do this in PHP?
>
As an alternative to what others have suggested, you could also do the
following:
Say, you want to map http://host/path/33 to http://host/path/?id=33
1. Have the ErrorDocument directive pointing to a file that can handle the
request; let's call it "redirect.php":
ErrorDocument 404 redirect.php
2. In redirect.php, the requested URL can be retrieved from the
$_SERVER['REQUEST_URI'] variable, which can be parsed as follows:
if (preg_match("#^/path/(\d+)/*$#", $_SERVER['REQUEST_URI'], $match)) {
header("Location: http://{$_SERVER['HTTP_HOST']}/path/?id=$match[1]");
exit;
} else {
// Display error message
}
JW
Navigation:
[Reply to this message]
|