[SOLVED] Url concatenation error when deploying to AWS S3

Hi everyone,

I had a problem when deploying my Hugo site from Gitlab to AWS S3. The routing doesn’t work as I expected. For home page, It should be:

S3_BUCKET_NAME/index.html

And when SUB_FOLDER_NAME in nav bar gets clicked, it should be:

S3_BUCKET_NAME/SUB_FOLDER_NAME/index.html

However it will concatenate the new url with the previous url, for example after SUB_FOLDER_NAME in nav bar is clicked, the new url becomes

S3_BUCKET_NAME/S3_BUCKET_NAME/SUB_FOLDER_NAME/index.html

which is wrong. Any thoughts on this issue? Thanks!

Problem solved! Please refer to answer from @RickCogley in the comments.

We can’t know unless we see your site’s source files. Completely guessing, your templates or baseURL is loading relative links throughout. For more help, please link to your site’s files. :slight_smile:

Hi Maiki, thanks for helping out, the url of my site is statds.org, you will be able to observe the url behavior if you click buttons in nav bar.

Here is the gitlab repo for my site:

I see what you mean. I also notice that on the other pages the menu works normally. Test it on http://statds.org/template/, menu works.

Unfortunately, I don’t have a lot of experience with menus. It’s strange, because the menu in your config matches the menu in the theme’s exampleSite config.

You can try searching these forums for discussions about menu links, there might be a solution. Or, you could open an issue with the theme author. And someone else will probably come along and know the answer. :slight_smile:

Scratch that, I think it is something about your index page and S3. When I clone your site, it works fine locally. It works for you, too? Maybe something with the aws s3 sync.

To test it, I’d manually upload the index.html from your local public directory, and see if that fixes it. Then you know where it is breaking. :slight_smile:

I think it is the interaction of .URL being called by the template for the menu, and your URL settings in your config.toml.

Have a look at: Template menu generation .URL messed up using relativeURLs: true

Thank you so much for your help! It’s indeed weird that the url works on http://statds.org/template/. And the whole site works perfectly in my local host as well. I also think it’s a problem with the CI process with S3, I will keep trouble shooting this and update the post if the problem is solved.

Hi Rick, you’re right about it. I checked the post and used | absURL after each .URL call in the layout files and set the relURL as false in config files. Then after deployment the urls function as expected. Thanks a lot for your help! Saved a lot of time for me.

1 Like

Hi al I’m still desperately struggling with this issue with the Airspace Themefisher theme. The layouts folder contains only references to BaseURL (i.e. {{ .Site.BaseURL }}img/logo.png). I’ve tried changing the config.toml to have relativeURLS = false but that doesn’t seem to work.

The website has been working as expected locally…Should I change the theme’s layouts as per tracyghz to add absURL everywhere where I BaseURL?

I’m not sure why I should change the theme to begin with, since that’s supposed to be correct?