views:

146

answers:

2

I want to have my site urls look like

http://example.com/place/info?var=info&morevars=ifneeded

Place and info are also variables but they have a fixed name, the ones after would vary. EDIT This is the url I am trying to rewrite

http://example.com/test.php?place=test&action=info&var=info&morevars=ifneeded

This is what I have so far

RewriteEngine on

RewriteRule ^([A-Za-z0-9-]+)/?$ test.php?place=$1 [NC]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ test.php?place=$1&action=$2 [NC]

I think there a way to do this with {QUERY_STRING} but I can't get it to work just 500 errors or it don't make a differences. Thanks for all of your help!

A: 

You're missing the first /

RewriteEngine on

RewriteRule ^/([A-Za-z0-9-]+)/ test2.php?place=$1 [NC]
RewriteRule ^/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/ test2.php?place=$1&action=$2 [NC]
SpliFF
Scott
The leading slash is only necessary if you want to use the rule in the server or virtual host configuration. In .htaccess, the contextual per-directory prefix is removed before testing the rules.
Gumbo
+1  A: 

You have set the QSA flag that automatically appends the original requested query to the new one:

RewriteEngine on
RewriteRule ^([A-Za-z0-9-]+)/?$ test.php?place=$1 [NC,QSA]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ test.php?place=$1&action=$2 [NC,QSA]
Gumbo
Thanks, never would have found that in all of the apache docs without you!
Scott