1. Caddy version (caddy version
):
root@caddy:~ # caddy version
v2.4.6 h1:HGkGICFGvyrodcqOOclHKfvJC0qTU7vny/7FhYp9hNw=
2. How I run Caddy:
a. System environment:
root@caddy:~ # uname -a
FreeBSD caddy 12.2-RELEASE-p10 FreeBSD 12.2-RELEASE-p10 b26f74b5984(HEAD) TRUENAS amd64
b. Command:
service caddy start
c. Service/unit/compose file:
n/a
d. My complete Caddyfile or JSON config:
Frontend Caddy reverse proxy (relevant extract)
...
(proxy-host) {
@{args.0} host {args.0}.udance.com.au
reverse_proxy @{args.0} {args.1}
}
...
import proxy-host blog 10.1.1.54
...
Backend Caddy web server serving WordPress PHP files.
{
# debug
log {
format json {
time_format iso8601
}
}
}
:80 {
log {
format json {
time_format iso8601
}
output file /var/log/caddy/access.log {
roll_keep 7
}
}
root * /usr/local/www/wordpress
encode gzip zstd
php_fastcgi 127.0.0.1:9000 {
env SERVER_PORT 80
}
file_server
# External access denied to these files.
@forbidden {
not path /wp-includes/ms-files.php
path /wp-admin/includes/*.php
path /wp-includes/*.php
path /wp-config.php
path /wp-content/uploads/*.php
path /.user.ini
path /wp-content/debug.log
}
respond @forbidden 403
# Mitigate spam attack logins and comments
@protected path_regexp (wp-comments-posts|wp-login)\.php$
handle @protected {
@no-referer {
not header Referer https://{host}*
method POST
}
abort @no-referer
}
}
3. The problem I’m having:
A couple of years ago, I moved my blog site off a somewhat restrictive subdomain of wordpress.com (hendroff.wordpress.com) and decided to self-host at blog.udance.com.au. I managed to export the site off wordpress.com and successfully imported the site to a local instance of WordPress. Text and media came across successfully.
It’s recently come to my attention though that hyperlinks to other blog posts were not updated. Clicking on these on the relocated site would send me back to a post on the old site.
For example, clicking on the link below in the blog post Digitising VHS Tapes: Part 1(3) – Digitising Process Considerations…
In Part 2 of this series, I attempt a repair on my failed Samsung VCR.
…sent me off to the old site article https://hendroff.wordpress.com/2017/05/16/digitising-vhs-tapes-part-23/
instead of the equivalent new site article https://blog.udance.com.au/2017/05/16/digitising-vhs-tapes-part-23/
4. Error messages and/or full log output:
n/a
5. What I already tried:
I can probably use a WordPress plugin such as Go Live Update Urls to search and replace instances of the old URL with the new one, but this seems a bit like a sledgehammer approach. I’m sure I can do better.
There are at least three Caddy directives that I feel might do the job for me (see the next section), but:
- I’m not sure which is the right tool for the job; and
- I lack the confidence and know-how to apply the tool.
For instance, I note that the only difference in the hyperlink example I provided above is the domain name so I tried the following in the hope that it would work. but it didn’t.
uri replace /hendroff.wordpress.com/ /blog.dance.com.au/
Is there a way to use Caddy to address this issue with a bit more finesse and elegance than the approach the plugin uses?