I am using a redirection plugin and want to redirect the existing search url

http://www.example.com/search/abcdef to http://www.example.com/?s=abcd

I am able to redirect /search/abcdef to /?s=abcdef however I can't get hold of how to trim and use the first of characters of search term i.e abcd in short it should look like /?s=abcd

As of now I am using following regex with plugin:

Source URL - /search/(.*)

Target URL - http://www.example.com/?s=$1

I'd appreciate any pointers in that direction or maybe a working answer ;)

  • 1
    How are you redirecting? There are already close votes on this question for being off-topic and I am tempted to add one unless I see some valid WordPress components. – s_ha_dum Sep 24 '13 at 15:09
  • Maybe I am not being clear as to what I want. Here's the plugin I am using for handling redirection - wordpress.org/plugins/redirection As already mentioned above, I have already modified the "/search/abcdef" part of url to match that of wordpress inbuilt search mechanism. What I am trying to accomplish here is to extract first 4 characters of "abcdef" and use it with "/?s=" parameter. I hope it makes some sense now. – Paritosh Sep 24 '13 at 16:28
  • Please don't comment, but add that as edit instead. – kaiser Sep 29 '13 at 6:25

No need for a Regex. There's substr( $string, int $offset ); built into PHP to achieve that.

  • True. But I am specifically looking out for a regex to achieve the same since the plugin I am using (Redirection) requires regex. – Paritosh Sep 24 '13 at 14:42
  • 1
    @Paritosh So Google was no option? ... ^[a-zA-Z0-9]{4}$ for alphanumeric first four characters... – kaiser Sep 24 '13 at 14:45
  • Yes, it was and is an option but I can't find a related topic. String matching results dominate my queries. Hence the thought of posting here :) – Paritosh Sep 24 '13 at 14:48
  • @Paritosh What I showed you in above comment (the working Regex), was extracted from the first search result in above linked Google search results page ;) – kaiser Sep 24 '13 at 14:50
  • 1
    Are you serious, @Paritosh ? You've now gotten an analogous function as well as a regex. – Johannes Pille Sep 24 '13 at 15:06

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.