<p><a href="http://buildwithcraft.com/docs/templating/redirect" rel="nofollow">Redirecting</a> to the first result is simple...</p>

<pre><code>{% if results|length == 1 %}
    {% redirect results[0].url %}
{% endif %}
</code></pre>

CC BY-SA 3.0
2015-10-27T19:18:21.600Z
2015-10-27T19:18:21.600Z
Lindsey D
<p>When performing a search on the front-end, is it possible to have two different behaviors, depending on the number of results?</p>

<ul>
<li>With more than one result, show the normal "results" page.</li>
<li>With only a single result, <strong>automatically redirect to that entry page.</strong></li>
</ul>

CC BY-SA 3.0
2015-10-27T19:07:19.853Z
I've reworded the question based on what I believe you are after... Please feel free to roll it back (or edit further) if I am mistaken!
Lindsey D
CC BY-SA 3.0
2015-10-27T19:27:59.353Z
Ahhh... thanks for the edit / translation @Lindsey.
carlcs
<search>
Front-end searching: Automatically redirect when only 1 result
# Front-end searching: Automatically redirect when only 1 result

(Asked by: username_0 on 2015-10-27)

When performing a search on the front-end, is it possible to have two different behaviors, depending on the number of results?

* With more than one result, show the normal "results" page.
* With only a single result, **automatically redirect to that entry page.**

**Tags:** search
> **Comments:**
> **username_1**: I've reworded the question based on what I believe you are after... Please feel free to roll it back (or edit further) if I am mistaken!  
> **username_2**: Ahhh... thanks for the edit / translation @Lindsey.  

---

## 1 answers

### Answer by username_1 on 2015-10-27. Score: 2 | Accepted answer

Redirecting to the first result is simple...
{% if results|length == 1 %}
    {% redirect results[0].url %}
{% endif %}


---

