WordPress Shortlinks Interfering with wget Mirroring

Testing some methods to convert a WordPress site into a static site, I ran into a weird problem when converting the links (using -k or --convert-links in wget) was breaking the mirroring process, putting in the wrong links.

My mirror command was simply:

wget -m -k -nH example.com

The link conversion ended up breaking the internal links – a link like:

<a href="about/index.html">[ About ]</a>

… was being converted into

<a href="index.html?p=2">[ About ]</a>

I was a bit stumped until I noticed that the About page contained the following HTML:

<link rel='shortlink' href='https://example.com/?p=2' />

Removing the shortlink by simply adding the following line to wp-config.php (although it should probably go in the theme) fixed the problem:

remove_action('wp_head', 'wp_shortlink_wp_head');

My guess is that wget sees the shortlink declaration and tries to helpfully rename the files to match, but this ends up just breaking the link conversion, rendering the mirror useless.

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.