...

View Full Version : Simple Mod Rewrite Question



fl00d
10-30-2007, 02:28 AM
Hi,

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...

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

jlhaslip
10-30-2007, 06: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.
:)

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum