I've set up a rule to rewrite a query string. Although the redirection is correctly performed, a % character is appended to the rewritten query portion of the URL, like so:


instead of


The rewrite rule is set as follows:

RewriteCond %{REQUEST_URI}  ^/site-search\.html$
RewriteCond %{QUERY_STRING} ^searchword=(.*)$
RewriteRule ^(.*)$ http://www.example.com/index.php?option=com_finder&view=search&f=1&Itemid=365&q=%1 [L,R=301]

My aim is to rewrite




Is there anything wrong in the syntax?


You are very close to the right format.

Try changing the last part of the last line

from &q=%1 [L,R=301]

to &q=$1 [L,R=301]

  • Tried that tweak before. Regrettably, it adds the query condition to the URL, not the search phrase. That is to say, q=site-search.html is appended, instead of q=search%20phrase – manchine Jul 4 '14 at 18:00
  • Any idea as to what might be wrong in the syntax? – manchine Jul 6 '14 at 16:34

I ran into the same problem with Apache/2.2.15. My solution was to use a RewriteMap with the "unescape" internal function. Using this twice performs a double URL decode, working around the issue.

A demonstration using your example:

RewriteMap unesc int:unescape

RewriteCond %{REQUEST_URI}  ^/site-search\.html$
RewriteCond %{QUERY_STRING} ^searchword=(.*)$
RewriteRule ^(.*)$ http://www.example.com/index.php?option=com_finder&view=search&f=1&Itemid=365&q=${unesc:${unesc:%1}} [L,R=301]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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