This is my first posting here. I’m very new to Hugo and not exactly brilliant when it comes to the technical side, so please be gentle
Before my question, I want to express my gratitude both to @spf13 for creating Hugo and to this whole community for giving so freely of their time and knowledge. I’ve learned a lot just lurking here.
Thank you all.
So onto my question. I’m migrating an existing site to Hugo and as part of the migration I’m tidying up a few things. Most of the pages that are being culled can be easily redirected through an alias in the respective destination page’s front matter.
However, a few pages are being repurposed as sections within larger pages. So for instance:
http://example.com/news
will now be at a section (id=“news”) on another page, and will be found at:
http://example.com/recent#news
Clearly I can redirect to the /recent page. My question is: is it possible–and if so, how–to redirect to an anchor on a page (in this example, the news anchor).
Ah, you are absolutely right. My apologies, I had not understood your question completely.
Have you looked at the meta-tag refresh? Technically you should be able to generate pages with the meta tag (you need to have a different partial header or use a new type for these pages) and then use the ref function to link to the new page#anchor.
What I’ve done is follow the system for aliases that Hugo uses. So for the old URLs that I want to be redirected, I’ve put a corresponding folder in the static folder. Inside the “old URL” folders (in my earlier example static/news) I’ve created an index.html file with the refresh tag that redirects to the new page#anchor link (in this example it refreshes to http://example.com/recent#news).
@spc are you creating separate folders and index.html files manually within static? Your best bet is to just add the appropriate alias in the front matter of the new content piece. If I understand what you are saying correctly, you don’t have to worry about the hash in your alias since the browser will just go to that page regardless and stops routing up to that symbol in the URL. Have you tried the following?
<!--content/articles/my-new-page.md-->
---
title: My New Page and URL
date: 2016-02-23
aliases:
- /my-old-url
-/another-old-address#anchor
---
Thanks for your thoughts @rdwatters, but I don’t get how this helps me.
I’m trying to redirect a url TO an anchor on a separate page. Unless I’m not understanding, your suggestion does the opposite (linking an anchor to a page).
I was also looking for this feature. We’re combining several old pages to a single one and we’d like to add anchors to redirect the user to the right location. It would be cool to have a way to pass a hash along to the redirected page…