<p>Routes can't include query strings. A route is a path to a template file (or a controller action, if you've written a custom plugin).</p>

<p>You can retrieve a query string value from within a template using the <a href="https://craftcms.com/docs/templating/craft.request#getParam" rel="nofollow noreferrer"><code>craft.request.getParam</code> method</a>.</p>

<p>For example:</p>

<pre><code>{% set token = craft.request.getParam('token') %}
</code></pre>

<h2>Update</h2>

<p>Following the conversation in the comments, here is an example of this working with a standard Craft route.</p>

<p>My example route <code>/querystring/test</code> points to the template <code>_views/querystring-test.twig</code>, which contains the following example code.</p>

<pre><code>&lt;h1&gt;Query String Test&lt;/h1&gt;

{% if craft.request.getParam('example') %}
    &lt;p&gt;The query string value for &lt;code&gt;example&lt;/code&gt; is "{{ craft.request.getParam('example') }}",&lt;/p&gt;
{% else %}
    &lt;p&gt;There is no query string parameter.&lt;/p&gt;
{% endif %}
</code></pre>

<p>Here is a screenshot of the page <em>without</em> a query string:</p>

<p><a href="https://i.sstatic.net/JLS2Y.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/JLS2Y.png" alt="enter image description here"></a></p>

<p>And here is a screenshot of the page <em>with</em> a query string:</p>

<p><a href="https://i.sstatic.net/PjFZB.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/PjFZB.png" alt="enter image description here"></a></p>

CC BY-SA 3.0
2017-05-24T18:32:42.413Z
I'm just trying to make sure that the template file loads even though the URL has a query parameter. I'm thinking that should be possible and that it is a rather common use case. Am I wrong?
Kristian S. Munkvold
CC BY-SA 3.0
2017-05-24T19:53:49.087Z
The route will match, and the template will load, regardless of whether the URL contains query parameters.
Stephen Lewis
CC BY-SA 3.0
2017-05-24T22:16:34.123Z
I thought that would be the case, but if you have a look at the screenshots above – that's not what's going on. Any ideas of what might be wrong here?
Kristian S. Munkvold
CC BY-SA 3.0
2017-05-25T00:20:21.813Z
Have you tried appending the query string to `/test/register`, without the trailing slash?
Stephen Lewis
CC BY-SA 3.0
2017-05-26T08:21:58.943Z
Yes, and I get the same result. Whenever I introduce a Query Parameter the result is "page not found" on all the routes.
Kristian S. Munkvold
CC BY-SA 3.0
2017-05-26T10:29:04.627Z
This doesn't sound like a Craft problem. I'm guessing it's an issue with your Apache or nginx configuration. I've updated my answer to include details of my working example.
Stephen Lewis
CC BY-SA 3.0
2017-05-26T10:49:16.010Z
Oh. After quite some time debugging we figured out that we're using a reserved Query Parameter. It works fine with anything besides the Query Param "token". (https://craftcms.com/docs/config-settings#tokenParam)

We'll do the name change. ;)
Kristian S. Munkvold
CC BY-SA 3.0
2017-05-24T17:31:51.840Z
2017-05-26T10:27:45.633Z
2017-05-26T10:27:45.633Z
Stephen Lewis
<p>I am currently setting up routes for a one-page application. As soon as a Query Parameter is introduced, the route fails. The route "test" replaces "my-av1" in the following photos.</p>

<p>The documentation in Craft does not describe how Query Parameters are handled. How do I proceed from here?</p>

<p><a href="https://i.sstatic.net/k7whh.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/k7whh.png" alt="Routes should work as described – but as soon a Query Parameter is introduced in the url, the route stops working."></a>
<a href="https://i.sstatic.net/c61G1.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/c61G1.png" alt="The route &quot;test&quot; replaces my-av1"></a></p>

<control-panel><routes>
How do you handle routes in CP with Query Parameters?
# How do you handle routes in CP with Query Parameters?

(Asked by: username_0 on 2017-05-24)

I am currently setting up routes for a one-page application. As soon as a Query Parameter is introduced, the route fails. The route "test" replaces "my-av1" in the following photos.

The documentation in Craft does not describe how Query Parameters are handled. How do I proceed from here?

[![Routes should work as described – but as soon a Query Parameter is introduced in the url, the route stops working.](https://i.sstatic.net/k7whh.png)](https://i.sstatic.net/k7whh.png)
[![The route ](https://i.sstatic.net/c61G1.png)](https://i.sstatic.net/c61G1.png)

**Tags:** control-panel, routes


---

## 1 answers

### Answer by username_1 on 2017-05-24. Score: 2

Routes can't include query strings. A route is a path to a template file (or a controller action, if you've written a custom plugin).
You can retrieve a query string value from within a template using the craft.request.getParam method.
For example:
{% set token = craft.request.getParam('token') %}

Update
Following the conversation in the comments, here is an example of this working with a standard Craft route.
My example route /querystring/test points to the template _views/querystring-test.twig, which contains the following example code.
Query String Test

{% if craft.request.getParam('example') %}
    The query string value for example is "{{ craft.request.getParam('example') }}",
{% else %}
    There is no query string parameter.
{% endif %}

Here is a screenshot of the page without a query string:

And here is a screenshot of the page with a query string:

> **Comments:**
> **username_0**: I'm just trying to make sure that the template file loads even though the URL has a query parameter. I'm thinking that should be possible and that it is a rather common use case. Am I wrong?  
> **username_1**: The route will match, and the template will load, regardless of whether the URL contains query parameters.  
> **username_0**: I thought that would be the case, but if you have a look at the screenshots above – that's not what's going on. Any ideas of what might be wrong here?  
> **username_1**: Have you tried appending the query string to `/test/register`, without the trailing slash?  
> **username_0**: Yes, and I get the same result. Whenever I introduce a Query Parameter the result is "page not found" on all the routes.  
> **username_1**: This doesn't sound like a Craft problem. I'm guessing it's an issue with your Apache or nginx configuration. I've updated my answer to include details of my working example.  
> **username_0**: Oh. After quite some time debugging we figured out that we're using a reserved Query Parameter. It works fine with anything besides the Query Param "token". (https://craftcms.com/docs/config-settings#tokenParam)  We'll do the name change. ;)  

---

