Categories and pages with the same url

Hi there,

I am unable to find a solution, in Hugo I need to create a .md page to add content but the directory I want to add the content is /properties however to make the content easily filterable I am using category which also name /properties

how can I use the content directory /properties and use categories /properties and make Hugo aware to generate only category pages and do not generate any /directory urls?

# content
content/properties/
# URL created 
example.com/properties

#categories pages auto generated by Hugo
/properties
# URL created
example.com/properties/

I need to have the content directory as I need to add those pages somewhere. so how can I solve this issue can I tell Hugo the content/properties/ is actually a category?

Thanks

Generate categories with different url through your config file

[permalinks]
  categories = "/category/:slug/"

Hi @idarek

I do not want to generate a different url I am happy with the url

# URL created by category
example.com/properties/

I just want to avoid duplicate pages also created by the directory

I cannot just not add /properties in the directory folder as Hugo needs this pages to generate content

So I am unable to find a solution or tell Hugo that the content in the directory /properties is actually the category properties

Thanks

If you don’t want duplicate pages, you perhaps should not use a category with the same name as a section. Or not use categories at all.

You’ll probably not get different answers by asking the same question in different posts, btw.

Dear @chrillek

Please do not jump into a post if you cannot provide some value to it.

If I was able to use a category with different name that would have been easier of course.

As a beginner I am wondering and exploring how Hugo works and how to make different things work here.

So please let me share my issue as I hope to get some tips or tricks on how to solve this.

Thanks

Please do not ask the same question in different threads.

You are completely free to chose the name of your category. What you’re saying (if I understand you correctly) is this:

  • I want categories
  • I want a category to be “properties”
  • I want a section that’s named “properties”
  • I don’t want the section and the category to be duplicates

I don’t understand

  • Why you think that would be a problem (given that you could rename the section or the category or both to anything you fancy)?
  • Why you think that you need categories as well as sections?
  • If you’ve played around with some sample documents to see what happens you can do and how the website generated by Hugo will be organized

Hi @chrillek

The categories of properties > sale/rent > residential/commerical is what I want and I am glad Hugo generates these for me and it is really easy to create navigations for this.

However I need to create page for these listings in the content directory and I name the directory /properties now the issue is if I change the content directory to for example /listings this is going to create a duplication issue for me as I am going to have same page generate twice

# The category page 
example.com/properties/sale/residential/apartment/property-id-234233

# And the page url which Hugo generates
example.com/listings/property-id-234233

changing the category or content directory name does not solve my issue. I want Hugo to generate only 1 page and I prefer the way categories work however I need to also add content in the content directory which also creates the same page twice.

Since listings grow quickly duplication is going to create mess both for SEO and for the site size.

I have searched a lot Hugo but did not find how to solve the duplication issue

thanks

Hm. I have a very small travelling blog, using two taxonomies:

  • continents
  • countries

The possible terms for these taxonomies should be obvious.

Suppose I have a blog text in
content/blog/my-trip-to-france
with the obvious front matter values

continent: Europe
country: ["France"]

When I generate my site with Hugo, I get three directories under public:

blog/my-trip-to-france
continent/europe
country/france

but only blog/my-trip-to-france contains the blog text itself. The other two directories contain only index.html files that list the relevant content (in the way that I want it to be listed). I do not see any duplication there.

It would help if you posted a link to your GitHub repository here so that someone could see what you’re actually doing and perhaps fix whatever needs fixing.

1 Like

Hi @chrillek

You mean

category /listings & content directory /properties will produce

# directory /properties/ property-1
example.com/properties/property-1

# category listing
example.com/listing/ 

# which show all listings under that category will show single page as
example.com/properties/property-1

# instead of 
example.com/listings/property-1

# it will not create duplicate urls
example.com/listings/property-1
example.com/listings/for-sale/property-1
example.com/listings/for-sale/residential/property-1
example.com/listings/for-sale/residential/apartment/property-1
example.com/listings/for-sale/residential/apartment/1st-floor/property-1

using the directory path for me is impossible since I have for example

properties/sale/residential/apartment/france/lyon/2nd-floor/340000-euro/

So this make it a very long sub directory paths

Thanks

Post a link to your repo. There’s no point in discussing that further without seeing your code.

Hi @chrillek

I do not have any repo I am using the giraffe academy Hugo theme and just trying to organise content to see how categories and directories can work together but from what I understand it doesn’t.

Maybe I leave the property directory as it is and use categories from one step down instead of properties I start categorising from sale/rent

Thanks it does help even if we communicate without understanding what the issue and solution is.

Actually issue remains which is the directory and category conflict

if I have a category called properties and then sub categories such as sale/rent I can easily navigate and end to the property page with all the properties.

But if I have the category listings or if I do not use the main category I cannot end up to the properties page :frowning:

my desired path is

example.com/properties/ which is generated from the Hugo content directory

and then start using subcategories such as sale or rent, residential or commercial etc.

and when I am at sale for example I can go back to properties

should I use

[permalinks]
  categories = "/properties/:slug/"

so the subcategories can lead back to the main properties page or my brain have given up in understanding Hugo?

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.