0

Possible Duplicate:
Mod Rewrite and Using PHP’s GET for URL’s When not Following the Rules

I've been scratching my head over this for days... I have a instance where a URL needs to pass different variables on a $_GET string.

I'm looking to parse the following URL:

http://www.domain.com/1/count/?var1=a&var2=b

Basically, I need to parse count as a $_GET['var3'] variable along with other additional vars appended after the trailing slash (?var1=a&var2=b).

I've tried the following along with many other options, but it results in a 404:

RewriteRule ^1/(count|list|detail)$/$ /1/service.php?method=$1
RewriteRule ^1/(count|list|detail)$/$ /1/service.php?method=$1&$2?

I've scoured many docs and answers, but I can't find an applicable answer and admit, it's driving me slowly insane!

Any help would be graciously accepted and appreciated.

Community
  • 1
  • 1
nickhar
  • 19,981
  • 12
  • 60
  • 73
  • Are you asking for `[QSA]` or do you have different URL schemes to match? Why do you have two `$` end markers in the regex? – mario Oct 19 '12 at 22:53
  • Only one URL schema and I've got two $ as I understood that each could be marked as interpreting a different variable ($1, $2 - if both were listed). – nickhar Oct 19 '12 at 22:55
  • In the replacement part, yes. But only if you have two match groups. That's a different meaning than in the regex. – mario Oct 19 '12 at 22:56
  • @mario Got it. Understand multiple matching groups, just failed to appreciate the [QSA] option. Thanks. – nickhar Oct 19 '12 at 23:23

2 Answers2

3

you want to use [QSA], Query String Append. Read about it here. If this is what you want in your browser:

http://www.domain.com/1/count/?var1=a&var2=b

You should put this in your htaccess file

RewriteRule ^(count|list|detail)/$ /service.php [QSA]

I removed some of the things from your rule above, not knowing your system, I'm not sure what they were there for. What is the 1 and the duplicate $ for?

This rule will send domain.com/count/?t=5 to domain.com/service.php?t=5

Landon
  • 4,088
  • 3
  • 28
  • 42
  • No. '1' just maps to a directory /1/ where service.php is located. But would this list/use 'count' as a $_GET variable in addition to 't' in your example? – nickhar Oct 19 '12 at 23:03
  • +1 as you helped drive the answer I was looking for. Thanks. – nickhar Oct 19 '12 at 23:27
1
RewriteRule ^/?1/(count|list|detail)/?$ /1/service.php?method=$1 [QSA]
Ωmega
  • 42,614
  • 34
  • 134
  • 203