View Full Version : Simple Mod Rewrite Question

10-30-2007, 03:28 AM

I've been recently reading up on Apache's mod rewrite feature. At the moment I'm a bit puzzled about how it works exactly but I'll figure it out eventually. Anyways, my question is do I have to write a rewrite rule for every page?

For instance, say I want news.php?cat=tech&id=2 to be like /news/tech/2/
and tutorials.php?cat=html&id=65 to be like /tutorials/html/65/, would I have to have a separate rewrite rule for each? 2 different pages = 2 different rules?
Or is there a one way all page sort of thing?

I'm guessing its a rule for every page...

One more thing, do I still use $_GET (ex: $_GET['cat']) for the variables? Or do I need to explode it?

10-30-2007, 07:02 AM
No, you can write a rule using Regex that handles a wide variety of files according to parameters you define.
here is an example:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z_]+)/([^/]+) index.php?category=$1&title=$2 [L]Keep reading.

10-30-2007, 06:23 PM
Useful Resource: http://forum.modrewrite.com/