Is it possible to create redirects in WebHelp Responsive?

Post here questions and problems related to editing and publishing DITA content.
TumasN
Posts: 21
Joined: Sat Jun 24, 2023 7:35 pm

Is it possible to create redirects in WebHelp Responsive?

Post by TumasN »

My team decided to change the name of one of our products and the URLs in our documentation (i.e. the topic names) reflected the old name of the product. I will have to change the topic filenames and, hence, the resulting URLs in WebHelp Responsive, but I don't want to leave the search engines and the users hanging in case they bookmarked an old name.

Is there any way to create new topics with old names that would be converted during publishing to WebHelp Responsive into HTML redirects? Such as <meta http-equiv="refresh" content="0; url=http://example.com/" />? And then, how to add these topics to the map so that they're not actually displayed anywhere, but still converted into HTML when the map is processed?

To make sure it's understood correctly, if I have a topic called old_product_name.dita, I will rename that file into new_product_name.dita, and I would like to create an old_product_name.dita file that will not have any content (or just information about redirecting) but would be converted into HTML with a redirect to new_product_name.html.
TumasN
Posts: 21
Joined: Sat Jun 24, 2023 7:35 pm

Re: Is it possible to create redirects in WebHelp Responsive?

Post by TumasN »

I found a method that is not very elegant at all and I hope there is a better way of doing that:

1. Create a redirects.xml file with a JavaScript script in the publishing template, like this:

Code: Select all

<script type="text/javascript"><!--
    switch (window.location.pathname)
    {
      case "/topics/old_url_1.html":
        window.location.href = "new_url_1.html";
        break;
      case "/topics/old_url_2.html":
        window.location.href = "new_url_2.html";
        break;
      default:
        break;
      }
-->
</script>
2. Create topic files: new_url_1.dita, new_url_2.dita etc.
3. Put the topic files in the map with toc="no"
4. Modify the template, adding:

Code: Select all

<fragment placeholder="webhelp.fragment.head" file="html-fragments/redirects.xml"/>
The ugliness of this solution is that the script is in every single topic HTML output file, and it just causes a redirect if the URL matches one of the redirect URLs.

Anyone has any idea of any other solution for this?
Post Reply