3

My search form is returning all of the sites pages, regardless of the search term used.

Even if I search for a load of random letters (dfbdsufbsf) all pages are returned.

This is my search form code. I've tried changing the button to and but no joy

      <form class='form form--search' role='search' action="{{ url('search/results') }}">
        <fieldset>
          <div class='input'>
            <label class='hidden' for='q'>Search</label>
            <input class='form__input form__input--search' placeholder="Search" name='q' id="q" tabindex='1' type='search'>
            <button class='form--search__button' type="submit"></button>
          </div>
        </fieldset>
      </form>

And here is my search results page (search/results.html) (markup removed)

{#
 # Search template
 # ---------------
#}

{% extends "_layout" %}
{% block content %}
  {% set query = craft.request.getParam('q') %}
  {% set entries = craft.entries.search(query).order('score') %}

    <h1 class='hero__title hero__title--news'>Search Results</h1>
    {% if entries|length %}
        <p>{{ entries|length }} results:</p>
    {% else %}
        <p>Your search for “{{ query }}” didn’t return any results.</p>
    {% endif %}


    {% if entries|length %}
        {% for entry in entries %}
            <a href="{{ entry.url }}">{{ entry.title }}</a>
        {% endfor %}
    {% endif %}

{% endblock %}

Any ideas why this is happening. I'm using the latest version of Craft. This is happening locally and on production.

  • I have the same problem but I don't have anything in my htaccess. Is it normal that when I'm searching for 'test' and click on the search button it returns me all pages and the URL is : index.php?Q=test. – rdomingue Aug 6 '15 at 1:02
2

Sorted.

It was a .htaccess issue

One of my redirects had a typo in it

RewriteRule ^old-page$ /new-page [R=301,L#]

should be

RewriteRule ^old-page$ /new-page [R=301,L]
| improve this answer | |

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.