How could make baseURL settings support multi domains?

Hi guys:

I’m come from China user of Hugo, when we visited to github pages service that sometime is miss. So there need backup a pages in China land. Now I come true sync github repository code to other Chinese repository, when github build pages code(static files) would auto sync the Chinese repository. But found that the baseURL were fixed, so when visited Chinese pages service and clicked page’s link that would jump to Github pages, there was not good.

My site build with Hugo CLI like this:

hugo -b https://xxxx.github.io/demo/ --minify

At first I think the baseURL parameter will support subfolder , then I tried some command in local like this:

hugo server -b demo or hugo server -b demo/
## output visit url: //demo:port/

hugo server -b /demo/
## output visit url:  //C:1414/Program%20Files/Git/demo/

Actually I want it could generate relative path with subfolder which name is demo, Then when visited different domain as below it can jump right things.

https://xxxx.github.io/demo/
https://xxxx.gitee.io/demo/
https://xxxx.coding.net/demo/

So is there some way can set baseURL not full domain & subfolder, just with the subfolder then it could be generate once code and bind with different domain more easy.

Hmm…

I’m not sure what your setup is but hugo -b https://sub.domain.tld/subfolder/ should work.

For example:

  • hugo -b https://sub.domain1.tld/subfolder/
  • hugo -b https://sub.domain2.tld/subfolder/
  • hugo -b https://sub.domain2.tld/subfolder/

Since you are mirroring your Github repo in a China-hosted git repo, you can do it two ways

  • 1st method: Use hugo -b https://sub.domain2.tld/subfolder/
  • 2nd method: Add the environment variable HUGO_BASEURL with a value of https://sub.domain2.tld/subfolder/

There is another way, by setting a different destination path for built files. I think the command is hugo -d so say hugo -b https://sub.domain2.tld/subfolder/ -d /public_domain2/. Then you can set your domain name to point to that folder. (note: I haven’t tried this setup, it may or may not work.)

Thanks for the warning, append my github action flow description as below:

name: Deploy Preliminary Site

on:
  push:
    branches:
      - develop

jobs:

  build-deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
          fetch-depth: 0 

      - name: Setting variable
        env:
          ADD_THIS_ID: ${{ secrets.ADD_THIS_ID }}
          ANALYTICS_LA_ID: ${{ secrets.ANALYTICS_LA_ID }}
          WALINE_SERVER_URL: ${{ secrets.WALINE_SERVER_URL }}
        run: sh .github/scripts/replace-vars.sh

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: '0.100.1'
          extended: true

      - name: Build Site
        run: hugo -b https://hugo-next.github.io/hugo-next-docs --minify

      - name: Copy README & License
        run: |
              cp README.md README.zh.md ./public
              cp LICENSE ./public

      - name: Deploy Pages
        uses: peaceiris/actions-gh-pages@v3
        with:
          deploy_key: ${{ secrets.RSA_PRIVATE_KEY }}
          external_repository: hugo-next/hugo-next-docs
          publish_dir: "./public"        
          keep_files: false
          publish_branch: gh-pg
          commit_message: ${{ github.event.head_commit.message }}

      sync-2-gitee:
          runs-on: ubuntu-latest
          steps:
            - name: Sync to Gitee
              uses: wearerequired/git-mirror-action@master
              env:
                SSH_PRIVATE_KEY: ${{ secrets.GITEE_RSA_PRIVATE_KEY }}
              with:
                source-repo: git@github.com:hugo-next/hugo-next-docs.git
                destination-repo: git@gitee.com:hugo-next/hugo-next-docs.git

My requestment is that I’m want once generate site statics file then use page services in anywhere.

That’s good idea but it’s mean I need myself server envrionment which could done more custom settings.

So I don’t want fixed the -b parameter setting, maybe it could sets /hugo-next-docs , and then when user visited under domain hugo-next.github.io all href will appen baseURL with domain, the link come be like this https://hugo-next.github.io/hugo-next-docs/post/. I don’t known it there could be support this.

That’s true, you will have to customize your server environment and other related settings.

Unfortunately, at least as far as I know, it is not possible the have multi-domain support by just setting up the path.

I haven’t tried an empty baseURL, baseURL = "", I’m not sure how it will affect other functions of Hugo (like URL generations for assets, permalinks, etc.) Maybe someone tried this before.

1 Like

Thanks your tips, keep wait for other more better ideas.

You can configure multiple languages, each with its own baseURL; when you run hugo server you will get multiple servers running, each on its own port.

Thanks @bep suggest, but in here I want to backup site all things to other repository. But when Hugo generate static site files were with baseURL settings , so that only one domain could be set in. Maybe I need build tow times with different domain settings and push each other.

Ok, there I found more & more history discusses in forum, then found that could use canonifyURLs: true parameter to keep the Permalink with subfolder then use Hugo build command same as the github-action-script .

Becase the page have creative commons links need full links so can’t without baseURL.

Preview this effect as below:

Hope it could be help you fix same problem.

1 Like

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