2

I'm trying to make a clean url for a blog on a dynamic website, but I think that the problem is that I don't know how to plan the website schema.

I read about how to use mod_rewrite and all I found is how to make "http://www.website.com/?category&date&post-title" to "http://www.website.com/category/date/post-title". that's works o.k for me.

The problem is that If my url looks like "http://www.website.com/blog/?id=34" this method won't work as far as I got it.

So, I have two questions: 1. Is there a way to use mod_rewrite (maybe read from a txt file) to read the post title of my blog and rewrite my url by date and post-title? 2. Should I rewrite my website to query the data from one index file in the homepage and use mod_rewrite to write the nice url? should I query also the date and the title of the post instead just the post ID?

3 Answers 3

2
  1. mod_rewrite used to rewrite requests and it has nothing to do with urls. You have to change urls by hands.
  2. yes, it's most common practice, to query the data from one index file
    no, you can't use mod_rewrite to write the nice url
    yes, an id must be present in the url along with title. your engine will just throw title away and use only id to retrieve an article.

Take a look at SO urls for an example

1
  • Thanks 2# It make sense... and I don't use mod_rewrite to write the nice url, I'm writing the nice url and the mod_rewrite redirect the page behind the scenes. Mar 28, 2010 at 15:04
1

What you're talking about is commonly referred to as routing and lots of examples exist of different ways to do it with PHP. The most common approach uses the frontcontroller pattern, which means in the simple case rewriting all URLs to a single php file and then having that file determine what content to show dynamically based on the URL.

The most popular PHP frameworks (CakePHP, Symphony, Codeigniter, etc.) all have routing code in them which you might be able to use or might serve as inspiration. Alternatively this article covers lots of the basics if you want to do it yourself: http://www.phpaddiction.com/tags/axial/url-routing-with-php-part-one/

2
  • the link to phpaddiction.com is broken Jan 10, 2011 at 16:14
  • mmm, appears to have been a temporary glitch, I'm seeing the site back up now.
    – Garethr
    Jan 11, 2011 at 11:26
0

RewriteMap allows you to do all sorts of dynamic rewriting (text file, script, etc).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.