Forum

Thread tagged as: Question

Clean URLS on search

Wondering if it is possible to generate clean urls on the search results page using the out-of-the-box search functionality included in Perch. (To clarify: I'm not referring to cleaning up the link in search-result.html, but rather the URL of the actual search generated by search-form.html.)

What I'd like:

  1. Type a search term into the text input (ex: foo)
  2. Redirect to a search results page that looks like /search/foo

What I've done:

  1. Written the HTACCESS snippet
  2. Moved /search.php to /search/index.php (so the rule doesn't loop forever)
  3. Changed the search-form.html template to:
<perch:form id="search" method="get" action="/search">

Which results in a URL like:

www.example.com/search/?q=foo

When I want to have...

www.example.com/search/foo

I thought the rewrite attribute on the perch:form tag might work, but I can't seem to figure it out.

Any thoughts?

Richard Terrick

Richard Terrick 3 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

When you send a form via an HTTP POST request, the data is sent in the headers to the URL specified in the action attribute.

When you send via HTTP GET, the URL in the action attribute is appended with the data as a query string.

Those are the two options, really. That's just how HTTP works. To get the URL you want, you'll need to set the form to submit to a script that gathers the data and then redirects to the new URL.

Thanks for the info, Drew!