views:

44

answers:

2

I need to replace the encoded value for the & sign in my url so the search query is successful. Im struggling to copy a similar method from the solution in this post for a query string such as below.

lovelakedistrict.com/result/?q=Brookfield+Bed+%2526+Breakfast

I want it to be like so

lovelakedistrict.com/result/?q=Brookfield+Bed+&+Breakfast

The reason being is that the url with the %2526 is indexed in google and is obviously broken.

+1  A: 
RewriteCond %{QUERY_STRING} (.*?)%(25)+26(.*?%(25)+26.*)
RewriteRule ^ %{REQUEST_URI}?%1+%3 [N]
RewriteCond %{QUERY_STRING} (.*?)%(25)+26(.*)
RewriteRule ^ %{REQUEST_URI}?%1+%3 [L,R=301]

(copied from the link you posted changing 20s into 26s)

aularon
AJFMEDIA
+2  A: 

As aularon said, it should be Bed+%26+Breakfast, as & is a query string parameter separator. (You'll notice if you follow the second link you are actually searching for “Brookfield Bed ”.)

<form id="form" action="/result" method="get">

Results in a correct query like:

http://www.lovelakedistrict.com/result?q=Brookfield+Bed+%26+Breakfast

However, since /result is a folder, the web server redirects that query to /result/, and for some reason changes the query string at the same time, double-encoding it to %2526.

I don't know why it does that, it's not normal Apache behaviour—have you got some dodgy rewrite rules maybe?—but you should be able to avoid it by pointing the form at the proper URL:

<form id="form" action="/result/" method="get">
bobince