Redirect error pages

We have the following scenario:
stores.brand.com/az/nonexistentcity

  • Will this redirect to a 404 page?
  • Can I know on the 404 template what the original URL was (the one causing the 404)?

Basically the client wants that if I go to stores.brand.com/az/nonexistentcity I would be redirected to stores.brand.com/az, or if I go to stores.brand.com/az/phoenix/nonexistentlocation I would be redirected to stores.brand.com/az/phoenix, but if I go to stores.brand.com/nonexistentcity then I would be redirected either to the Locator or the root on the Directory Manager.

Is there a way to handle this scenario?

Hi Alejandro,

You can use the Dynamic Redirects feature to accomplish exactly this, without worrying about handling the redirect yourself on the 404 page.

For example, you could setup Dynamic Redirects with the following configurations:

dynamicRoutes:
  - from: /:state/:city
    to: /:state
    status: 302
  - from: /:state/:city/:location
    to: /:state/:city
    status: 302

In Pages, Dynamic Redirects are only checked if there is not already content for that URL, so these would only redirect if the page would end up 404ing without the Dynamic Redirects.

Best,
Saswata

That is great!
Can I add query strings in order to know when I load the state template that I should show a message (Sorry we couldn’t find the city you are looking for but this are all the cities for {state})?
Do I need to upgrade to the last version of Pages JS for this to work?

1 Like

Query params are not supported in the paths used in Dynamic Redirects as of now. I’m not sure there’s currently any identifier for when a Dynamic Redirect routed a user to a page, sorry about that.

1 Like