views:

182

answers:

2

I'm a mod_rewrite noob and I'm getting a headache trying to figure out something that should be simple. What I'm trying to do is strip out unwanted variables from a URL displayed after a GET form is used. In other words, I'm trying to change this:

stats.php?gender=W&team_id=88&btnGet=Get+Stats

to this:

stats.php?team_id=88

Please help me!

EDIT: All I had to do was remove the "name" attributes in my form on 'gender' and the submit button. Thanks to too much php and Gumbo for the solution! Of course, there was a much easier way of accomplishing this. :)

+2  A: 

What would this even achieve? The URL will still appear exactly the same in the user's address bar, and PHP is more capable of ignoring abitrary $_GET variables than mod_rewrite will ever be.

Try removing 'name="btnGet"' attribute from your submit button and drop the 'gender' field as well. You can also use Javascript to dynamically remove form elements which aren't needed.

too much php
+1  A: 
RewriteCond %{QUERY_STRING} team_id=([0-9]+)
RewriteCond %{QUERY_STRING} btnGet
RewriteRule stats.php stats.php?team_id=%1 [R]

You can't match query strings with RewriteRule -- you have to use RewriteCond.

As "too much" says, just doing the rewriting won't cause any visible change to the user unless you reload the page. So you need the [R] to force a redirect instead of a simple rewrite, which may not work for the logic of your program.

Devin Ceartas