1

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:

index.php?option=com_finder&view=search&f=1&Itemid=365&q=the%2520emperor%2527s%2520new%2520school

instead of

index.php?option=com_finder&view=search&f=1&Itemid=365&q=the%20emperor%27s%20new%20school

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

site-search.html?searchword=someword

as

full-site-search?q=someword

Is there anything wrong in the syntax?

2

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
1

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.