mod_rewrite and php. 500 points.

i've never looked at mod_rewrite before, so i'm a little confused. if i get my apache server to rewrite this page:

/products.php?id=10

to:

/products/10/index.php

how does products.php know which item to show? the $_GET or $_REQUEST arrays either no longer exist (in the case of $_GET) or no longer contain the 'id' key. i have a horrible feeling that i'll then have to do something like exploding $_SERVER["PHP_SELF"] and pulling apart the url until i find the number, but i'm hoping it isn't as complicated as this, and i'm doing something wrong. afterall, if you were rewritting:

? so, firstly, what appears in the browser location, the nice one (/10/index.php)? secondly, how do i link to that page, by using the nice one or the bad one. if i use the bad one and mod_rewrite translates it into the good one, my users would still be able to see where the bad one was pointing (in the status bar or source code) so i don't want that.

well, everything you describe is how i saw mod_rewrite working, but the reality is different. i *must* be doing something wrong.

this is my .htaccess file:

RewriteEngine On
RewriteRule ^products/([0-9]+)/ /products.php?id=$1

it obviously works because when i hit /products/10/ i get my file, and not a 404. however, i'm spitting out the $_REQUEST array and the $_GET array and neither contain anything. when i hit /products.php?id=10, the same file tells me that an id of 10 has been passed. so where am i going wrong?

and sorry from me, i didn't take it as an insult, i appreciate your help.

well *that* is the strangest thing. while sitting here i found someone having the same problem on google, which he then fixed. the only difference i could see in the before and after was that he used two arguments. so i tried:

RewriteRule ^([a-z].*)/([0-9]+)/$ products.php?test=$1&id=$2

and it works fine. and that's exactly what you've just posted.

but if you then edit it so it only uses one argument, for example:

RewriteRule ^products/([0-9]+)/$ products.php?id=$1

it doesn't work!

so does that mean that you *must* pass more than one match for mod_rewrite to work? seems strange.

>> Yes, in order for the rule to work, you have to pass the number of arguments the rule expects.

but thats where i'm confused. if i write this:

RewriteRule ^products/([0-9]+)/$ products.php?id=$1

surely the rule is only expecting one argument? then is only one reg_ex on the left to match ([0-9]+), there's only one reg_ex container on the right ($1) and there's also only one url argument passed (id=), but it doesn't work. what makes it expect 2 or more in this case?

Featured Post

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.