|
Posted by purcaholic on 08/07/07 09:48
On 7 Aug., 11:11, Geradeaus <ben.brughm...@gmail.com> wrote:
> I use mod_rewrite all the time, but I was still asking myself how you
> combine it with a database.
>
> e.g. you have an article with the title : "Mac, windows or linux. Who
> will tell?"
>
> so I can get something like this : http:///www.domain.com/article/mac-windows-or-linux-who-will-tell
> What should I do?
>
> 1. just urlencode the title (but then I have problems with the ,
> and .)
>
> 2. use a regular expression to filter out the special characters
> (replace spaces and ", ." by "-" ... etc) and save the filtered-title
> into the database? When I want to search for this article I just
> perform a regular expression on the title string and search for it in
> the databse: WHERE title = ".regularexpressionfunction($title)."
>
> 3. Or don't you save this title into the database, but do you always
> perform this regular expression while searching in the database? e.g.
> WHERE REGEX(title) LIKE '".regularexpressionfunction($title)."'
>
> I have been googling for a long time, but I can't find a descent
> article about this ...
>
> thanks for your help!
In my opinion the best way to handle article titles in url's is to
store them into the database as an additional table field. A field
named 'title' contains article title and 'urltitle' contains the
prepared title used for urls.
You don't need to search inside 'urltitle' use the real title instead.
'urltitle' is necessary if you want to link to the results.
If someone requests the page http://www.domain.com/article/mac-windows-or-linux-who-will-tell,
apaches mod rewrite engine will maybe pass this to an script as an
parameter value pair like article=mac-windows-or-linux-who-will-tell.
Now, you can execute a statement like "select * from articles where
urltitle='mac-windows-or-linux-who-will-tell'" to get the content of
the article. This way requires urltitles to be unique, otherwise you
would get more results.
purcaholic
P.S.: You can also dive into the core of some blogs, cms, etc. to find
out, how they solved this...
Navigation:
[Reply to this message]
|