Help for international blog redirects.json and publishing post with same slug

Hi, there! (Note: I’m new so I can’t add links, so see domain as domain.com)

I’m running my blog in Ghost pro. It has 6 collections, each one with diferent topics related among them.

The structure was domain/collection/slug/ while all the content was focused in Chile. Now I’m expanding to Mexico and I need split content to domain/chile/ and domain/mexico/. I need the same collections in both countries, so 12 collections in total.

This is how my routes.yaml file looks like now (chile and mexico) :point_down:

routes:
  /:
    template: home
  /rss/:
    premalink: /rss/
    template: app-rss
    content_type: text/xml
  /chile/:
    permalink: /chile/
    template: page-chile
    data: page.chile
  /mexico/:
    permalink: /mexico/
    template: page-mexico
    data: page.mexico
collections:
  /chile/collection-1/:
    permalink: /chile/collection-1/{slug}/
    filter: tag:collection-1+tag:hash-chile
    template: index
    data: page.chile-collection-1
  /chile/collection-2/:
    permalink: /chile/collection-2/{slug}/
    filter: tag:collection-2+tag:hash-chile
    template: index
    data: page.chile-collection-2
  /chile/collection-3/:
    permalink: /chile/collection-3/{slug}/
    filter: tag:collection-3+tag:hash-chile
    template: index
    data: page.chile-collection-3
  /chile/collection-3/collection-4/:
    permalink: /chile/collection-3/collection-4/{slug}/
    filter: tag:collection-4+tag:hash-chile
    template: index
    data: page.chile-collection-4
  /chile/collection-5/:
    permalink: /chile/collection-5/{slug}/
    filter: tag:collection-5+tag:hash-chile
    template: index
    data: page.chile-collection-5
  /chile/collection-6/:
    permalink: /chile/collection-6/{slug}/
    filter: tag:collection-6+tag:hash-chile
    template: index
    data: page.chile-collection-6
  /mexico/collection-1/:
    permalink: /mexico/collection-1/{slug}/
    filter: tag:hash-mexico+tag:collection-1
    template: index
    data: page.mexico-collection-1
  /mexico/collection-2/:
    permalink: /mexico/collection-2/{slug}/
    filter: tag:hash-mexico+tag:collection-2
    template: index
    data: page.mexico-collection-2
  /mexico/collection-3/:
    permalink: /mexico/collection-3/{slug}/
    filter: tag:hash-mexico+tag:collection-3
    template: index
    data: page.mexico-collection-3
  /mexico/collection-3/clases/:
    permalink: /mexico/collection-3/collection-4/{slug}/
    filter: tag:hash-mexico+tag:collection-4
    template: index
    data: page.mexico-collection-4
  /mexico/collection-5/:
    permalink: /mexico/collection-5/{slug}/
    filter: tag:hash-mexico+tag:collection-5
    template: index
    data: page.mexico-collection-5
  /mexico/collection-6/:
    permalink: /mexico/collection-6/{slug}/
    filter: tag:hash-mexico+tag:collection-6
    template: index
    data: page.mexico-collection-6
taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/

This way I can use #tags for filtering content in index.hbs and post.hbs templates and extend default.hbs with the correct partial for navigation, lang and hreflang blocks.

What I want with all this is having posts targeting chile and mexico for example domain/chile/collection-1/this-post/ and domain/mexico/collection-1/this-post/. And having posts just for one country Ex. domain/mexico/collection-3/post-just-for-mexico/

The two problems:

1.- After mexico was added the structure changed from domain/collection-1 to domain/chile/collection-1/ and domain/mexico/collection-1/ so I need a redirect from all urls to domain/chile/. Below is what I tried to do in redirect.json but I got a loop.

2.- If a post is going to both chile and mexico, I have to publish two versions of it, one with tag:collection-1 and tag:#chile and the other with tag:collection-1 and tag:#mexico, this make the first post go to domain/chile/collection-1/post/ and the second one go to domain/mexico/coleccion-1/post. This is perfect because I use #chile and #mexico to filter the hrefland for each post. The problem is the slug for second post, while I try to repeat it ghost adds a “-2” or “-n” which broke my code for hreflang.

I left here my code for hreflang and the code in redirects.json

code for filtering hreflang :point_down:
(this e.g is for posts to chile but i have the same for posts to mexico. Before this. I’m filtering with #chile and #mexico. This code is used when the post has #chile)

{{#contentFor "hreflang"}}
        <link rel="alternate" hreflang="es-cl" href="{{@site.url}}{{url}}"/>
        {{#has tag="collection-1"}}
            <link rel="alternate" hreflang="es-mx" href="{{@site.url}}/mexico/collection-1/{{slug}}"/>
        {{else has tag="collection-2"}}
            <link rel="alternate" hreflang="es-mx" href="{{@site.url}}/mexico/collection-2/{{slug}}"/>
        {{else has tag="collection-3"}}
            <link rel="alternate" hreflang="es-mx" href="{{@site.url}}/mexico/collection-3/{{slug}}"/>
        {{else has tag="collection-4"}}
            <link rel="alternate" hreflang="es-mx" href="{{@site.url}}/mexico/collection-4/{{slug}}"/>
        {{else has tag="collection-5"}}
            <link rel="alternate" hreflang="es-mx" href="{{@site.url}}/mexico/collection-5/{{slug}}"/>
        {{else has tag="collection-6"}}
            <link rel="alternate" hreflang="es-mx" href="{{@site.url}}/mexico/collection-6/{{slug}}"/>
        {{/has}}
{{/contentFor}}

redirects.json :point_down:

[
    {
        "from": "/collection-1/",
        "to": "/chile/collection-1/",
        "permanent": true
    },
    {
        "from": "/collection-1/(.*)",
        "to": "/chile/collection-1/$1",
    },
    {
        "from": "/collection-2/",
        "to": "/chile/collection-2/",
        "permanent": true
    },
    {
        "from": "/collection-2/(.*)",
        "to": "/chile/collection-2/$1",
        "permanent": true
    },
    {
        "from": "/collection-3/",
        "to": "/chile/collection-3/",
        "permanent": true
    },
    {
        "from": "/collection-3/(.*)",
        "to": "/chile/collection-3/$1",
        "permanent": true
    },
    {
        "from": "/collection-3/collection-4/",
        "to": "/chile/collection-3/collection-4/",
        "permanent": true
    },
    {
        "from": "/collection-3/collection-4/(.*)",
        "to": "/chile/collection-3/collection-4/$1",
        "permanent": true
    },
    {
        "from": "/collection-5/",
        "to": "/chile/collection-5/",
        "permanent": true
    },
    {
        "from": "/collection-5/(.*)",
        "to": "/chile/collection-5/$1",
        "permanent": true
    },
    {
        "from": "/collection-6/",
        "to": "/chile/collection-6/",
        "permanent": true
    },
    {
        "from": "/collection-6/(.*)",
        "to": "/chile/collection-6/$1",
        "permanent": true
    }
]

Thanks a lot for your help.

Hey @fersam :wave:
If you’re expanding your site into multiple languages I’d recommend check out this tutorial on the official Ghost site:

Also if you’re a Ghost(Pro) customer you should be able to contact support directly for assistance support@ghost.org

I’m not sure about your redirects issue, but as for your slugs issue I would suggest not trying to match the slugs. Really if you’re creating translated articles you should generate the slug from the translated heading. Using a page URL using chile wording might not make sense when it’s for an article written in Mexican. Alternatively you could prefix your slugs with ws-cl- or ws-mx- respectively.

Hope this helps!

Hi Dave,

Definitely i’ll contact with support for help with the redirects.
About matching slug in posts I need something like this https://wordpress.stackexchange.com/questions/313422/how-do-i-use-the-same-post-slug-for-different-categories

The tutorial on the official Ghost site recomend adding hreflang in code inyector, but I want use these blocks in post.hbs (the code below is working, but without matching slugs in both posts chile and mexico, the hreflang tag has a broken links)

{{#post}}
    {{#has tag="#chile"}}
        {{#contentFor "lang"}}es-cl{{/contentFor}}
        {{#contentFor "hreflang"}}
                <link rel="alternate" hreflang="es-cl" href="{{@site.url}}{{url}}"/>
                {{#has tag="collection-1"}}
                    <link rel="alternate" hreflang="es-mx" href="{{@site.url}}/mexico/collection-1/{{slug}}"/>
                {{else has tag="collection-2"}}
                    <link rel="alternate" hreflang="es-mx" href="{{@site.url}}/mexico/collection-2/{{slug}}"/>
                {{else has tag="collection-3"}}
                    <link rel="alternate" hreflang="es-mx" href="{{@site.url}}/mexico/collection-3/{{slug}}"/>
                {{else has tag="collectrion-4"}}
                    <link rel="alternate" hreflang="es-mx" href="{{@site.url}}/mexico/collection-3/collectrion-4/{{slug}}"/>
                {{else has tag="collection-5"}}
                    <link rel="alternate" hreflang="es-mx" href="{{@site.url}}/mexico/collection-5/{{slug}}"/>
                {{else has tag="collection-6"}}
                    <link rel="alternate" hreflang="es-mx" href="{{@site.url}}/mexico/collection-6/{{slug}}"/>
                {{/has}}
        {{/contentFor}}
        {{> "header-chile"}}
    {{else has tag="#mexico" }}
        {{#contentFor "lang"}}es-mx{{/contentFor}}
        {{#contentFor "hreflang"}}
                <link rel="alternate" hreflang="es-mx" href="{{@site.url}}{{url}}"/>
                {{#has tag="collection-1"}}
                    <link rel="alternate" hreflang="es-cl" href="{{@site.url}}/chile/collection-1/{{slug}}"/>
                {{else has tag="collection-2"}}
                    <link rel="alternate" hreflang="es-cl" href="{{@site.url}}/chile/collection-2/{{slug}}"/>
                {{else has tag="collection-3"}}
                    <link rel="alternate" hreflang="es-cl" href="{{@site.url}}/chile/collection-3/{{slug}}"/>
                {{else has tag="collectrion-4"}}
                    <link rel="alternate" hreflang="es-cl" href="{{@site.url}}/mexico/collection-3/collection-4/{{slug}}"/>
                {{else has tag="collection-5"}}
                    <link rel="alternate" hreflang="es-cl" href="{{@site.url}}/chile/collection-5/{{slug}}"/>
                {{else has tag="collection-6"}}
                    <link rel="alternate" hreflang="es-cl" href="{{@site.url}}/chile/collection-6/{{slug}}"/>
                {{/has}}
        {{/contentFor}}
        {{> "header-mexico"}}
    {{/has}}
{{/post}}