Inconstant names on subdomain

My website is on a subdomain like So I set in the configuration file

baseurl = ""

However, then I had troubles.

When I start the server using hugo server, the address becomes http://localhost:1313/~phyw. However, when I build the site directly with hugo, the site is output into public/ instead of public/~phyw. This brings a few issues:

I want the home page to point to a static page. Thus I used the trick discussed here:, which is to add to index.html

{{ range .Data.Pages }}
  {{if eq .RelPermalink "/~phyw/index.html" }} {{.Content}} {{end}}
{{ end }}

Then the http server uses /~phyw/index.html but when exporting to public, /index.html is used.

Even worse, I am unable to put a custom css file to the static/css/ or static/phyw/css/. Nether of them work.

If I removed ~phyw in the baseurl, then all those problems are gone. But I have to eventually upload my site to the subdomain… Any ideas?

I found a partial fix myself: setting

canonifyurls = "true"

This fixes the first problem – the index.html position is now correct for both server and export modes. The css location is still not consistent. As a temporary workaround, I modified the template css.

Not sure whether this is the proper way.