Skip to main content
Redirects can enhance the search experience. For example:
  • Searching for โ€œhelpโ€ redirects users to a support page
  • Searching for a category, such as, โ€œTVโ€ redirects users to a category page
  • Searching for a specific product or brand redirects users to a seasonal promotional page for it
  • Searching for specific keywords related to an ongoing event, such as, โ€œmasksโ€, redirects users to a more specific landing page
This guide explains how to add redirects to InstantSearch through Rules and using custom data. Redirects are handled by Autocompleteโ€™s redirect plugin. However, if you donโ€™t use Autocomplete, you must handle redirects in InstantSearch:

Handle a Manual Editor rule redirect

If a redirect was created in the Manual Editor, handle it with InstantSearchโ€™s QueryRuleCustomData widget.

Configure a rule

To set up a rule that returns custom data whenever the query matches specific keywords, see Create a rule for returning custom data.

Configure the queryRuleCustomData widget

After setting up a rule that returns the custom redirect data, you can use the QueryRuleCustomData widget to update the page location when userData contains a redirect.
Kotlin
@Serializable
data class Redirect(val url: String)

val searcher = HitsSearcher(
    applicationID = ApplicationID("ALGOLIA_APPLICATION_ID"),
    apiKey = APIKey("ALGOLIA_SEARCH_API_KEY"),
    indexName = IndexName("YourIndexName")
)
QueryRuleCustomDataConnector<Redirect>(searcher) { redirect ->
    redirect?.url?.let {
        // perform redirect with URL
    }
}
โŒ˜I