John Siu Blog

Tech - Business Tool, Personal Toys

Hugo Static for Migration

☰ Table of Content

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 URLNew 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:

1
2
3
4
5
6
7
.
├── archetypes/
├── content/
├── public/
├── resources/
├── static/
└── themes/

/index.php/

Inside the static directory, create directory index.php:

1
2
3
└── static/
    └── index.php/
        └── index.html

Create index.php/index.html:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<!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:

1
2
3
4
5
6
└── static/
    ├── index.php/
    │   └── tag/
    │       └── index.html
    └── tag/
        └── index.html

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<!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

Update: 2020-08-28
comments powered by Disqus