Hugo Static for Migration

Table of Contents

Use Hugo static section to handle migration from other platform such as Ghost or WordPress.


Background

I have multiple posts about using mod_rewrite / redirect in various web servers to handle difference in base usr when migrating from one blog platform to another.

But what about /index.php and /index.php/tag(from WordPress) or /tag(from Ghost). They are generating lot of 404 in web server log.

Old URL New URL
/index.php /
/index.php/tag /tags
/tag /tags

Use Hugo /static/

You can create web server rules to handle them. But that is another 2 or 4 rules, depending on web server used and other rules already in place. And yes, they may conflict each other!

Luckily with Hugo there is a simpler solution then fiddling with web server rules. Your Hugo site directory tree should look similar to below:

.
├── archetypes/
├── content/
├── public/
├── resources/
├── static/
└── themes/

/index.php/

Inside the static directory, create directory index.php:

└── static/
    └── index.php/
        └── index.html

Create index.php/index.html:

<!DOCTYPE html>
<html>

<head>
  <title>/index.php</title>
  <link rel="canonical" href="/" />
  <meta name="robots" content="noindex">
  <meta charset="utf-8" />
  <meta http-equiv="refresh" content="0; url=/" />
</head>

</html>

/index.php/tag/ and /tag/

Inside the static directory, create directory index.php/tag and tag:

└── static/
    ├── index.php/
    │   └── tag/
    │       └── index.html
    └── tag/
        └── index.html

Create index.php/tag/index.html and tag/index.html:

<!DOCTYPE html>
<html>

<head>
  <title>/tag/</title>
  <link rel="canonical" href="/tags/" />
  <meta name="robots" content="noindex">
  <meta charset="utf-8" />
  <meta http-equiv="refresh" content="0; url=/tags/" />
</head>

</html>

Conclusion

The static will be deployed into your public folder automatically when compiling the site. No web server rules required. This removes another layer of web server dependency from your site.

John Siu
Minimize the Effort, Maximize the Effect!
comments powered by Disqus