<p>It sounds like you might be trying to blend Craft/Yii routing with Rewrites (if you're coming from an Apache background).</p>

<p>I believe what Craft interprets this as is an attempt to map a request to <code>locations/or/my-entry-slug</code> to the <code>&lt;slug&gt;</code> (literal) action of the <code>locations</code> controller (which doesn't exist).</p>

<p>If you just want to render a template for these entries, you can set up your route like this:</p>

<pre><code>'locations/&lt;state:[a-z]{2}&gt;/&lt;slug:{slug}&gt;' =&gt; ['template' =&gt; 'locations/entry']
</code></pre>

<p>This way, you'll get a <code>state</code> and <code>slug</code> variable in the <code>templates/locations/entry.twig</code> template, with which you can look up the Locations Entry you want.</p>

<p>To troubleshoot further, we might need a bit more information about how your Locations Section is set up, and the goals for the route!</p>

<blockquote>
  <p>If you're just looking to capture and redirect legacy URLs, be sure and <a href="https://github.com/nystudio107/craft-retour" rel="nofollow noreferrer">check out the Retour plugin</a>.</p>
  
  <p>Additionally (and for anyone who finds this in the future), I'd recommend reviewing the <a href="https://docs.craftcms.com/v3/routing.html#advanced-routing-with-url-rules" rel="nofollow noreferrer">advanced routing</a> docs.</p>
</blockquote>

CC BY-SA 4.0
2019-01-10T16:51:53.643Z
Thank you! I had tried the `['template' => 'path']` method before but was trying to pass the slug in directly instead of pointing to the generic entry and loading the specific entry there. This worked perfectly!
slander
CC BY-SA 4.0
2019-01-10T04:45:03.473Z
2019-01-10T04:45:03.473Z
August Miller
<p>I'm trying to route users to a "locations" structure entry that normally has a URL structure that looks like: <code>locations/&lt;slug&gt;</code></p>

<p>My client wants to use the structure of links from their old site to preserve SEO and wants to have the URL structure of: <code>locations/&lt;state&gt;/&lt;slug&gt;</code> 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.</p>

<p>In routes.php I have the following rule:</p>

<p><code>'locations/&lt;state:[a-z]{2}&gt;/&lt;slug:{slug}&gt;' =&gt; 'locations/&lt;slug&gt;'</code></p>

<p>But when I try to hit a route (for example <code>locations/ca/slug-name</code>) I get an InvalidRouteException and an error message saying: </p>

<p>Unable to resolve the request "locations/slug-name"</p>

<p>So it looks like it's stripping out the state parameter successfully but I'm not sure why <code>locations/slug-name</code> isn't recognized as a valid route.</p>

<p>Is there something I'm missing? Is there an easier way to do this? </p>

<config><routes><routing><regex>
Routing: How can I ignore a parameter in route definition?
# Routing: How can I ignore a parameter in route definition?

(Asked by: username_0 on 2019-01-10)

I'm trying to route users to a "locations" structure entry that normally has a URL structure that looks like: `locations/`

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//` 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//' => 'locations/'`

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?

**Tags:** config, routes, routing, regex


---

## 1 answers

### Answer by username_1 on 2019-01-10. Score: 3 | Accepted answer

It sounds like you might be trying to blend Craft/Yii routing with Rewrites (if you're coming from an Apache background).
I believe what Craft interprets this as is an attempt to map a request to locations/or/my-entry-slug to the  (literal) action of the locations controller (which doesn't exist).
If you just want to render a template for these entries, you can set up your route like this:
'locations//' => ['template' => 'locations/entry']

This way, you'll get a state and slug variable in the templates/locations/entry.twig template, with which you can look up the Locations Entry you want.
To troubleshoot further, we might need a bit more information about how your Locations Section is set up, and the goals for the route!

If you're just looking to capture and redirect legacy URLs, be sure and check out the Retour plugin.
Additionally (and for anyone who finds this in the future), I'd recommend reviewing the advanced routing docs.

> **Comments:**
> **username_0**: Thank you! I had tried the `['template' => 'path']` method before but was trying to pass the slug in directly instead of pointing to the generic entry and loading the specific entry there. This worked perfectly!  

---

