Welcome Guest, Not a member yet? Register   Sign In
Search, readable URLs, disallowed characters and err 400. Help!
#1

[eluser]BilliamTheSecond[/eluser]
I'm trying to set up a fulltext search and still have a readable URL (instead of base64 encoding).
My search form submits to a controller function that looks kind of like this:
Code:
function validate() {
  $query = rawurlencode($this->input->post('query'));
  redirect("search/$query");
}
function search() {
  $query = rawurldecode($this->uri->segment(2));
  echo $query;
}
To deal with disallowed characters, I've extended CI_URI with this change here:
http://dragffy.com/blog/posts/codeignite...characters


Note: Can't type things like % 23 in this forum without it being replaced with the # character. Using {percent} instead.

Now, when I search for "test phrase", I'm redirected to
search/"test{percent}20phrase"
and
Quote:"test phrase"
is echoed out. That's working.

Three problems I'm having so far with this approach:

1) Searching for phrases with # characters, like test#phrase redirect me to
search/test{percent}23phrase
properly, but only
Quote:test
is echoed out.

2) Searching for phrases with % characters, like test%phrase redirect me to
search/test{percent}25phrase
and I now get a Bad request! Error 400
In fact, throwing {percent}25 into my URL anywhere causes this error.

3) Searching for phrases with / characters, like test/phrase redirect me to
search/test/phrase
and I get a 404.

[edit]Added #3
Any and all help appreciated.
#2

[eluser]BilliamTheSecond[/eluser]
I _think_ I've solved these three issues by adding the B flag to my index.php rewrite
Code:
RewriteRule ^(.*)$ index.php [B]
And setting
Code:
AllowEncodedSlashes On
in my virtualhost.

Not sure what this will break down the line, though. :/
#3

[eluser]victorche[/eluser]
A little bit late for an answer, but ... Try like this:
Code:
$query = rawurlencode(rawurlencode($this->input->post('query')));
Don't ask why ... It will maybe fix some of your problems.
#4

[eluser]Vangelis B[/eluser]
For future readers:

Depending on your apache version this one may be unsolvable and may require refactoring parts of your application. This is due to an apache bug. Read more about it here:
http://stackoverflow.com/questions/43904...-on-apache




Theme © iAndrew 2016 - Forum software by © MyBB