Newbie question alert.
I’m following the Routing guide to create a more SEO friendly version of my search results URLs.
I’m aiming to get a folder-like URL: mysite.com/search/searchquery
I know I’ll probably have to set up some sort of redirect. So when users access this URL they won’t get a 404 error. But I can’t seem to find any information about what kind of redirect or set up I need to configure on my DNS.
Could anyone please pint me in the right direction?
Hi gusvd and welcome!
You don’t actually want to perform redirects at the DNS level. The goal here is to have the URL structure for all possible paths route to your application, and then map to the state information Algolia needs to call the search API.
I would advise against putting the query itself into the path since it can very so much. You may want to consider using facet values for the path (category, etc) and keeping the search query itself in the query string (
mysite.com/search/category?query=searchquery). As our documentation says:
For your search results to be part of search engines results, you have to be selective. Adding too many search results inside search engines could be considered as spam.
As the page you linked to mentioned, our default router encodes/decodes the state into a query string, but you can also use the path to encode the state – it just means you’ll need to write your functions to translate between the path and the state.
This section gets into some of the details: Sync your URLs with InstantSearch.js | Algolia
You’ll want to make sure your application is listening across the entire subpath of
search/*) and then build the functions to do the translation. As the page mentions, you’ll want to consider URL encoding for spaces and other non-URL friendly characters, and also maybe doing translation to shorten/simplify URLs.