<p>You should be able to use <a href="https://craftcms.com/docs/4.x/routing.html#advanced-routing-with-url-rules" rel="nofollow noreferrer">dynamic routes</a> to do exactly what you want.</p>
<p>Create a new route in the <code>config/routes.php</code> and point it to a twig template.</p>
<pre class="lang-php prettyprint-override"><code>return [
  // Route /en/category/city to a template
  '/en/&lt;category:{slug}&gt;/&lt;city:{slug}&gt;/' =&gt; ['template' =&gt; 'pages/_city'],
];
</code></pre>
<p>In the template (located at templates/pages/_city.twig if you used the template above) you can now access the variables <code>category</code> and <code>city</code> as we defined them in the route.</p>
<pre><code>&lt;p&gt;Get the best {{ category }} in {{ city }} and don't forget to follow us.&lt;/p&gt;
</code></pre>
<p>That said, on a personal note, this looks pretty spammy and could become problematic for you, if you are looking for good search engine rankings. Hope it works!</p>

CC BY-SA 4.0
2024-03-14T18:26:46.500Z
Glad it's not just me that thought this was spamtacular. I'd definitely expect it to do more harm than good - not just for SEO but for brand reputation.
James Smith
CC BY-SA 4.0
2024-03-15T06:17:39.900Z
I won't max it out and I plan to hyper-localize the pages which I can also use for Google Ads campaigns. Technically, I will try this approach.
flip
CC BY-SA 4.0
2024-03-19T09:17:53.380Z
I'd expect page rank to fall off a cliff and ad revenue along with it.
Seth Warburton
CC BY-SA 4.0
2024-03-26T16:38:13.407Z
Worth noting this recent post/warning from Google about changes related to their ranking algo with regards to auto-generated content: https://blog.google/products/search/google-search-update-march-2024/ - especially the bit entitled "Scaled content abuse"
James Smith
CC BY-SA 4.0
2024-03-14T17:48:40.340Z
2024-03-14T17:48:40.340Z
Max Strebel
<p>I would like to setup many pages (eventually 500-5,000) where only certain variables such as <strong>category</strong> and <strong>city</strong> change. The idea is that each page is optimized for a certain category and city. Setting up each page manually would cost a lot of effort plus it won't be sustainable. If I change the text for one category / city, I would like to apply it to all pages. Did anyone setup something similar with Craft CMS and can recommend a general best practice approach?</p>
<p>My idea is as follows but I haven't tried it yet and I am not sure if it is possible and a good approach:</p>
<ol>
<li>Import the list of categories and cities directly into the Craft CMS database, e.g. as channels. I can get the regional data from geonames.org.</li>
<li>Setup a template with fix content which is the same for all pages. Within this template, I will use variables to insert the category and city. Example:</li>
</ol>
<blockquote>
<p>Lorem ipsum dolor {{Category}} sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea {{City}} commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</blockquote>
<ol start="3">
<li>Use a URL structure as follows to open the pages which load the templates and insert the right variables:</li>
</ol>
<blockquote>
<p>domain.com/en/{{Category}}/{{City}}</p>
</blockquote>
<blockquote>
<p>domain.com/en/{{Category}}</p>
</blockquote>
<p>So, if someone implemented something similar and would share his experience, it would be awesome.</p>
<p>Thanks a lot,</p>
<p>Philip</p>

<craft-features><channels>
Directory-like page structure for many categories and cities
# Directory-like page structure for many categories and cities

(Asked by: username_0 on 2024-03-14)

I would like to setup many pages (eventually 500-5,000) where only certain variables such as **category** and **city** change. The idea is that each page is optimized for a certain category and city. Setting up each page manually would cost a lot of effort plus it won't be sustainable. If I change the text for one category / city, I would like to apply it to all pages. Did anyone setup something similar with Craft CMS and can recommend a general best practice approach?

My idea is as follows but I haven't tried it yet and I am not sure if it is possible and a good approach:

1. Import the list of categories and cities directly into the Craft CMS database, e.g. as channels. I can get the regional data from geonames.org.
2. Setup a template with fix content which is the same for all pages. Within this template, I will use variables to insert the category and city. Example:

> Lorem ipsum dolor {{Category}} sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea {{City}} commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

3. Use a URL structure as follows to open the pages which load the templates and insert the right variables:

> domain.com/en/{{Category}}/{{City}}

> domain.com/en/{{Category}}

So, if someone implemented something similar and would share his experience, it would be awesome.

Thanks a lot,

Philip

**Tags:** craft-features, channels


---

## 1 answers

### Answer by username_1 on 2024-03-14. Score: 3 | Accepted answer

You should be able to use dynamic routes to do exactly what you want.
Create a new route in the config/routes.php and point it to a twig template.
return [
  // Route /en/category/city to a template
  '/en///' => ['template' => 'pages/_city'],
];

In the template (located at templates/pages/_city.twig if you used the template above) you can now access the variables category and city as we defined them in the route.
Get the best {{ category }} in {{ city }} and don't forget to follow us.

That said, on a personal note, this looks pretty spammy and could become problematic for you, if you are looking for good search engine rankings. Hope it works!

> **Comments:**
> **username_2**: Glad it's not just me that thought this was spamtacular. I'd definitely expect it to do more harm than good - not just for SEO but for brand reputation.  
> **username_0**: I won't max it out and I plan to hyper-localize the pages which I can also use for Google Ads campaigns. Technically, I will try this approach.  
> **username_3**: I'd expect page rank to fall off a cliff and ad revenue along with it.  
> **username_2**: Worth noting this recent post/warning from Google about changes related to their ranking algo with regards to auto-generated content: https://blog.google/products/search/google-search-update-march-2024/ - especially the bit entitled "Scaled content abuse"  

---

