Reply to Re: Pretty URLs

Your name:

Reply:


Posted by Janwillem Borleffs on 11/05/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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация