add_rewrite_rule not working for language specific characters

My default search query:

example.com/search/?search_text=keyword

What I want to transform it:

example.com/search/keyword

So I added this to my function.php

add_rewrite_rule('^search/([^/]*)?','index.php?pagename=search&search_text=$matches[1]','top');

Works fine for english alphabet but whenever I search a keyword in my language like this:

example.com/search/kırmızı

The title of the page becomes: k%C4%B1rm%C4%B1z%C4%B1 and no results returned.

Let me know if you need more details.

1 Answer
1

This is happening due to encoding. I assume you have a function in your search page, which you get and use search_text inside that template. You should decode the URL before doing so.

The urldecode() function would be what you are looking for. Your string is also UTF-8 encoded, so this is what you are going to need:

$string = utf8_decode( urldecode( $_GET['search_text'] ) );

Now you can use the decoded string in your search.

Leave a Comment