sandro87
sandro87

Hello, I'm new to octoberCMS! Consider that I've been developing with other type of CMSes where they usually deal with urls automatically. So let's consider we have a website with Countries with their relative States and Cities. All of these of course use relationships in Models.

If I create this page with the url

/:country-slug

I can easily access the content by querying the country slug

/usa

If I want to access the city of Philadephia I would have something like this

/:country-slug/:state-slug/:city-slug

So this would work

/usa/pennsylvania/philadelphia

BUT to make this actually work and unique you need to check that the Model "City" has that exact country and state connected to it. Otherwise if you only check the last parameters :city-slug this would create false or worse infinite duplicate content where every combination of state/country could work with Philadelphia so that this URL could work as well

/italy/california/philadelphia

Is this the correct way do it? So that every URL with multiple parameters needs to be checked manually in the backend? Or I missing something here? This method seems extremely complicated for very long URLs and not very practical for actual dynamic content.

mjauvin
mjauvin

Just use model relation queries as explained here:

https://octobercms.com/docs/database/relations#one-to-many

i.e.

$city = County::where('slug', $countrySlug)->first()
   ->states()->where('slug', $stateSlug)->first()
   ->cities()->where('slug', $citySlug)->first();
mjauvin
mjauvin

You may want to use/examine the Location Towns plugin as well:

https://octobercms.com/plugin/vojtasvoboda-locationtown

sandro87
sandro87

Hi mjuavin, so it is correct I must check for every url the parameters to avoid duplicate content?

1-4 of 4