WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As usual, rewrite stumped me! I've built a custom search for searching through comments and comment meta, using a flat table. I'm using a rewrite rule as follows:


I'm sending a query var 'args' which is group of key/val pairs to search against, to my custom template which has the sql and stuff. This works fine. My problem is, when I search as follows,


Here I'm sending no params, hence I want to either redirect to 404 or just redirect to that same template with args as blank, where I'd see that args is blank and hence show all the results directly. I wrote the rule:


But it still works as default search, searches for the keyword 'reviews' (like WP does for 'hello'.... /search/hello) and doesn't redirect to my template.

Any help on how to avoid this behavior?

share|improve this question

Have you tried:


instead? (Making the last / optional). If after flushing the rewrite rules that still doesn't work, check with Monkeyman rewrite analyzier and update the question with your findings.

share|improve this answer
up vote 0 down vote accepted

I used a jQuery trick to achieve this. I changed submit to a button and used jQuery to form the desired URL. If nothing was entered in the search form, then I redirected to the 404 URL.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.