@raamay
The question is: how would you like your URL to end up? You have to have some idea.
Anyway, the general use of this it to read the url
htxp://example.com/dir1/articles/2 as
htxp://example.com/dir1/index.php?categ ory=articles&id =2. Which is, I suspect, somewhat like you're after?
Anyway, I'll dive into it.
First, we turn the engine on.
If you're working in a directory other than
root, it is best to set the base dir. I'm not sure if this is necessary, because I remember not having to do this a while ago when running XAMPP, but since switching to EasyPHP, I've had to use it. So, set this to the dir you are currently working in. I am assuming you have the .htaccess file in the directory you want to work with. If you are rewriting the the root directory, you'll have to make according changes to the paths.
-
RewriteEngine On
-
# The .htaccess file is in /root/dir1/
-
RewriteBase /dir1/
-
Now we want the rule.
-
RewriteEngine On
-
RewriteBase /dir1/
-
RewriteRule ^([a-zA-Z_-]+)/([0-9]+)$ index.php?cat=$1&id=$2 [R]
-
^ Starts the rule. The regular expression (rule) basically looks for any alpha character, underscore and hyphen (a-zA-Z_-), and also allows for more than one occurence (+). The value found is then stored in a variable for later use ($1)*. Then we check for a forward slash. After that, we look for any numeric character, allowing multiple occurences. Again, this is stored in a variable for later use ($2). $ Ends the rule.
We next specify the url it should be interpreted as, using the stored variables. After this comes the flag [R] - this forces the URL to be rewritten, meaning the the URL will change. If you want the url to remain masked, you can omit this flag.
* Variables are stored successively, 1, 2, 3 ...
This should get you started.
If you have any questions, let us know.
- Markus.