Answers.Body: <p>If you go to <code>Settings &gt; Routes</code> in the CP you're able to add routes with wildcard characters like:</p>
  
  <pre><code>/search/*
  </code></pre>
  
  <p>and then point that to a template.</p>
  
  <p>You can also <a href="https://craftcms.com/docs/plugins/hooks-reference#registerSiteRoutes" rel="nofollow noreferrer">register site routes</a> in a plugin if you want to go down that route (no pun intended)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-08T09:52:54.963Z
Answers.LastActivityDate: 2016-12-09T08:41:21.887Z
Answers.LastEditDate: 2016-12-09T08:41:21.887Z
Answers.UserDisplayName: KnutSv
Answers.Body: <p>You forgot to setup the routes for your search URLs.</p>
  
  <p>In this case I’d recommend to use an advanced route with a regular expression, as it allows to use patterns that will ignore the slashes between your search terms. You’d setup the route in your craft/config/routes.php file (see <a href="https://craftcms.com/docs/routing#advanced-routing" rel="nofollow noreferrer">Advanced Routing</a> in the Craft docs).</p>
  
  <pre class="lang-php prettyprint-override"><code>return array(
      'search/(?P&lt;query&gt;.+)' =&gt; 'search/_result',
  );
  </code></pre>
  
  <p>This route matches all URLs which start with <code>search/</code>, populates a variable named <code>query</code> with everything that comes after the <code>search/</code> and routes the request to a template search/_result.html. </p>
  
  <p>In your template you can now use the <code>split</code> filter to get the individual words. You can then join them to a nice search string for your criteria model (see <a href="https://craftcms.com/docs/searching" rel="nofollow noreferrer">Search Syntax</a> in the docs).</p>
  
  <pre><code>{% set words = query|split('/') %}
  {% set searchParam = words|join(' OR ') %}
  </code></pre>
  
  <p>Using this Twig code you’d prepare a search string that finds elements containing “advanced” or “routes” for an example URL <a href="http://example.com/search/advanced/routes" rel="nofollow noreferrer">http://example.com/search/advanced/routes</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-08T19:50:56.167Z
Answers.Text: Thanks, this worked like a charm! Learned something new :)
Answers.UserDisplayName: Kitsune
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-08T09:55:32.563Z
Answers.LastActivityDate: 2016-12-08T09:55:32.563Z
Answers.UserDisplayName: carlcs
Body: <p>I can't find a way to clean up the search address from
  <code>/search/?q=.../</code> to <code>/search/query/</code>.</p>
  
  <p>I see ways of getting the last segment of the url with something like <code>craft.request.getSegment</code>. My other permalinks work fine, but for search I can't get the search template to pickup the <code>/query/</code> bit (results in a logical 404 page).</p>
  
  <p>So either it's my .htaccess (using the one provided) missing something. Or alter something else.</p>
  
  <p>Thanks for any help!</p>
  
Tags: <search><routes>
Title: Prettify search URL
ThreadText: # Prettify search URL
  
  (Asked by: username_0 on 2016-12-08)
  
  I can't find a way to clean up the search address from
  `/search/?q=.../` to `/search/query/`.
  
  I see ways of getting the last segment of the url with something like `craft.request.getSegment`. My other permalinks work fine, but for search I can't get the search template to pickup the `/query/` bit (results in a logical 404 page).
  
  So either it's my .htaccess (using the one provided) missing something. Or alter something else.
  
  Thanks for any help!
  
  **Tags:** search, routes
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2016-12-08. Score: 5 | Accepted answer
  
  You forgot to setup the routes for your search URLs.
  
  In this case I’d recommend to use an advanced route with a regular expression, as it allows to use patterns that will ignore the slashes between your search terms. You’d setup the route in your craft/config/routes.php file (see [Advanced Routing](https://craftcms.com/docs/routing#advanced-routing) in the Craft docs).
  
  ```php
  return array(
      'search/(?P<query>.+)' => 'search/_result',
  );
  
  ```
  
  This route matches all URLs which start with `search/`, populates a variable named `query` with everything that comes after the `search/` and routes the request to a template search/\_result.html.
  
  In your template you can now use the `split` filter to get the individual words. You can then join them to a nice search string for your criteria model (see [Search Syntax](https://craftcms.com/docs/searching) in the docs).
  
  ```
  {% set words = query|split('/') %}
  {% set searchParam = words|join(' OR ') %}
  
  ```
  
  Using this Twig code you’d prepare a search string that finds elements containing “advanced” or “routes” for an example URL <http://example.com/search/advanced/routes>.
  
  > **Comments:**
  > **username_0**: Thanks, this worked like a charm! Learned something new :)  
  
  ---
  
  ### Answer by username_1 on 2016-12-08. Score: 3
  
  If you go to `Settings > Routes` in the CP you're able to add routes with wildcard characters like:
  
  ```
  /search/*
  
  ```
  
  and then point that to a template.
  
  You can also [register site routes](https://craftcms.com/docs/plugins/hooks-reference#registerSiteRoutes) in a plugin if you want to go down that route (no pun intended)
  
  
  ---
  
  