I'm trying to route users to a "locations" structure entry that normally has a URL structure that looks like: locations/<slug>
My client wants to use the structure of links from their old site to preserve SEO and wants to have the URL structure of: locations/<state>/<slug>
where state is a 2 letter string. So, I'm trying to set up a route rule that just ignores the parameter and redirects to the regular route.
In routes.php I have the following rule:
'locations/<state:[a-z]{2}>/<slug:{slug}>' => 'locations/<slug>'
But when I try to hit a route (for example locations/ca/slug-name
) I get an InvalidRouteException and an error message saying:
Unable to resolve the request "locations/slug-name"
So it looks like it's stripping out the state parameter successfully but I'm not sure why locations/slug-name
isn't recognized as a valid route.
Is there something I'm missing? Is there an easier way to do this?