views:

255

answers:

2

Hi all I need a bit of getting a redirect working in mod_rewrite.

I need to redirect the following

http://mysite.com/dictionary/find?word=test

to

http://mysite.com/dictionary/find?w=test

I'm sure the solution is trivial enough but my knowledge of mod_rewrite and regular expressions is quite limited and I haven't been able to work out. This is what I have attempted so far to no avail.

RewriteCond %{QUERY_STRING} word= [NC]
RewriteRule ^/(.*)word=(\w+)/$ /w=$1 [L]

Any help would be much appreciated. Thanks.

+2  A: 

This should be sufficient for you...

RewriteRule (?|&)word=(\w+) $1w=$2

this will replace it even if combined with other parameters.Your attempt to only process the querystring is interesting, I have never used that and cannot answer to if it's possible.

As a sidenote, turn on:

RewriteLog "/var/log/apache2/rewrite.log"
RewriteLogLevel 2

for more useful feedback.

jishi
jishi
A: 

Try this:

RewriteCond %{QUERY_STRING} ^(([^&]*&)*)word=(.*)
RewriteRule ^dictionary/find$ $0?%1w=%3 [R=301,L]
Gumbo