3

Not sure what is happening but

{% set searchQuery = craft.request.getParam('q') %}

Does not seem to be working at all on a different server than staging. Anyone seen this before? Any ideas what could be preventing getParam from working? Here is what the end of my url looks like with the param: results?q=test

I then later try to display the search parameter like.

<h1 class="text-uppercase">Search Results {{searchQuery}}</h1>

But it only displays Search Results leaving the parameter empty... and my search results seem to be returning everything since it is basically doing a wildcard search since I'm using this below to query the matching results...

{% paginate craft.entries.search(searchQuery).order('score').limit(10) as entries %}

Everything works as expected on staging server.

  • Are you sure getParam is the issue? What happens if you {{ searchQuery }} immediately after {% set searchQuery = craft.request.getParam('q') %}? Does it output test? – Brad Bell Jun 30 '15 at 17:19
  • Outputs nothing, just like how its not outputting in the h1 I mentioned. – Bowenac Jun 30 '15 at 17:32
  • Maybe some .htaccess rewrite rule that's dropping query strings? – Brad Bell Jun 30 '15 at 17:44
  • It sure was, client added some odd rule. – Bowenac Jul 1 '15 at 3:26
  • Can you add that as an official answer? – Brad Bell Jul 1 '15 at 4:51
3

The client must have added a new rule which was causing the problem.

changed from

RewriteRule (.+) index.php?p=$1 [L]

to

RewriteRule (.+) index.php [L]

Not exactly sure why they added that but...

| improve this answer | |
  • I encountered a similar problem. I've been using the letter "p" as part of a search string so www.website.com/test?p=querystring. It worked for more 6 months and now all of a sudden it doesn't work. Thanks to this post I looked in my .htaccess file and see this rewrite rule: RewriteRule (.+) index.php?p=$1 [QSA,L] which was there by default when I installed Craft. I changed my query string parameter to "q" and now it works again. Not sure if something changed when I updated to the latest Craft version or if it's something else. – Lori Oct 12 '16 at 18:54

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.