Redirections

Redirections can be configured in the Redirections page and are used to redirect user to a custom route or external page when a specific search keyword is entered.

Redirections using LupaSearch Plugin

To use configured redirections, you must enable the setting in LupaSearch plugin configuration:

Activate the feature in Search Results or Search Box options:

const options = {
  // Other search box or search results options
  redirections: {
    enabled: true,
    queryKey: "",
    cacheSeconds: 3600,
    urlTransformer: (url: string) => {
      return `${url}`;
    },
  },
};

For consistent behavior, ensure that the configurations for both Search Box and Search Results components match, as the plugin will use the settings from the first component it renders.

  • enabled: enables the redirection feature when set to true.

  • qyeryKey: choose a query key that will reference search index from which to load redirection configurations from. Usually, this is your main document search key.

  • cacheSeconds - to reduce unnecessary API calls and enhance performance, redirection rules can be cached. A higher value is advisable if redirection rules change infrequently.

  • urlTransformer - customize or append to the redirection URL as needed. Useful for language-specific routing or other URL modifications.

Redirections using your own integration

Alternatively, you can use the Public redirections API endpoint to process redirection logic on your own.

To retrieve redirections for a specific index, issue an HTTP GET request to the following endpoint:

/v1/redirections/{queryKey}

Use any queryKey from your main DOCUMENT search index.

The response format will include a list of configured redirection keywords and target urls. For example:

{
  "rules": [
    {
      "source": "lego, apple, special-brand-name",
      "target": "/custom-special-brand-page/"
    },
    {
      "source": "apple",
      "target": "https://www.apple.com/"
    }
  ]
}
  • source - a comma-separated list of keywords that will trigger the redirection. Keywords should be case-insensitive.

  • target - a URL to redirect to. Can be a relative path or an absolute URL.

If you are using your own integration, you can use the source and target values to implement your own redirection logic when a user enters a specific keyword.

You can read more about the API endpoint in the API Reference: Public Redirections.