Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So i am trying to redirect from

index.php?action=search&query=search text goes here


search?query=search text goes here

i tried this so far but with no luck

RewriteRule ^search/? index.php?action=search&query=$1 [QSA,L]

EDIT : Solution was

RewriteCond %{QUERY_STRING}  ^query=(.*)$
RewriteRule ^search/? index.php?action=search&query=%1 [QSA,L]

and since i had some other RewriteRules in my htaccess i had to put them above them.

my other rewriterules were like this:

RewriteRule ^(\w+)/?$ index.php?action=$1
share|improve this question

migrated from Jun 9 '11 at 12:53

This question came from our site for professional and enthusiast programmers.

You mean the other way around? From search... to index.php?...? – Qtax Jun 9 '11 at 11:54
from index to search – fxuser Jun 9 '11 at 12:01
up vote 1 down vote accepted

Try this:

RewriteCond %{QUERY_STRING}  ^query=(.*)$
RewriteRule ^search/? index.php?action=search&query=%1 [QSA,L]
share|improve this answer
it still does show up the $_GET["query"] – fxuser Jun 9 '11 at 12:02
ok this seems to work but my other rewrotes affected it... thanks – fxuser Jun 9 '11 at 14:12
Are you able to get it working? Or you still having issues? If you still having issues please share your all rewrite rules. – Hameedullah Khan Jun 9 '11 at 15:17
i placed it on top and before my other rewriterules so its working now. – fxuser Jun 9 '11 at 16:15

You need to capture it into a capturing group.

RewriteRule ^search\?query=(.*)$ index.php?action=search&query=$1 [QSA,L]
share|improve this answer
i am trying to retrieve the $_GET["query"] but it doesnt seem to show up... so it seems its not working – fxuser Jun 9 '11 at 11:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.