Reputation: 1
I want to redirect the search result page to a new one. The old url looks like this:
/תוצאות_חיפוש:search_keyword
And I need it to look like this:
/?s=search_keyword&post_type=product
The search_keyword
is what the user looks for, meaning the term he's looking for. That means this shouldn't be changed. For example, if someone search for "shirts", the old url will look like:
/תוצאות_חיפוש:shirts
While the new one will look like:
/?s=shirts&post_type=product
I have tried multiple solution I found here on StackOverflow but none did the trick.
How can I create this redirect?
Upvotes: 0
Views: 93
Reputation: 74098
You must capture the search string and use it in the substitution URL
RewriteRule ^תוצאות_חיפוש:(.+)$ /?s=$1&post_type=product [L]
See RewriteRule
and Apache mod_rewrite Introduction for details.
Although, I've never seen anything beyond ASCII in .htaccess file, I just checked this in my test environment. Even though, Apache logs this request as
172.17.0.1 - - [12/May/2019:14:58:39 +0000] "GET /%D7%AA%D7%95%D7%A6%D7%90%D7%95%D7%AA_%D7%97%D7%99%D7%A4%D7%95%D7%A9:shirts HTTP/1.1" 200 268 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/73.0.3683.86 Chrome/73.0.3683.86 Safari/537.36"
in mod_rewrite the RewriteRule
receives it as decoded תוצאות_חיפוש:shirts
Upvotes: 1
Reputation:
Try use this:
url_string_name.replace(@"^\/תוצאות_חיפוש:", "/?s=");
This will replace the begining of the url. And then:
url_string_name.replace(@"$", "&post_type=product");
this will replace the end of the url;
^
means begin of string, $
means end of string.
Good Luck!
Upvotes: 0