Redirects

Redirects allows you to create a direct connection between a query or keyword and a specific url. When can you use it?
For example, you have a stand-alone product for one category, and you want to make it possible for your costumers to directly search for the product page from the search, without passing by the search page.
This guide will be divided into two sections. The first one is to show you how to create a Redirect for your store and the second part the additional steps you will have to follow if you have a custom API store.
Redirects also work with Omnisearch. It uses the same matching rules and sends visitors to the configured URL, so no separate Omnisearch setup is needed.
Creating Redirects #
Configure the query first, then choose where matching searches should lead.
- Go to Search > Redirects > New redirect.
- In Query, select Matches exactly or Contains. Matches exactly redirects only the exact word or phrase. Contains redirects when the term is part of a longer search.
- Enter the query terms in the single input. Add or remove terms as needed. The selected mode applies to these terms.
- Enter the destination URL below Query.
- Click Save.
API Setup #
If you have integrated Clerk with the API directly, the redirect link will be returned by the endpoints
search/predictive and
search/search for any queries that match the Redirect rules you created.
The Redirect URL will be included in the redirect key of the response.
Example:
# API Call
curl -X POST \
-H 'Content-Type: application/json' \
-d '{"key": "store_api_key",
"query": "softball",
"language": "english",
"limit": 6,
"visitor": "unique_visitor_id",
"labels": ["Instant Search"]}' \
http://api.clerk.io/v2/search/predictive
# Response
{
"status": "ok",
"query": "softball",
"count": 2,
"result": [
37217,
40058
],
"hits": 2,
"redirect": "https://www.thebaseballgeek.co.uk/softball"
}
Troubleshooting #
Many scripts add functionality to your search field, so if your redirect does not work, there is a good chance that another script is overwriting the functionality.
Below is an example of how you can overwrite existing functionality to force your Clerk redirects to be prioritised. It might require customisation for your setup.
<script>
(function() {
input_selector = document.querySelector('#{{ content.id }}').dataset.instantSearch;
document.querySelectorAll(input_selector).forEach(input=>{
input.addEventListener('keyup', function(event){
{% if redirect %}
var currentRedirect = '{{ redirect }}';
{% else %}
var currentRedirect = undefined;
{% endif %}
if(event.which == 13 || event.which == 'Enter'){
if(currentRedirect != undefined){
event.preventDefault();
window.location.replace(currentRedirect);
}
}
});
});
})();
</script>