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?


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.


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.

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.