Skip to content

Commit

Permalink
Replace all my Netlify redirects with Caddy config
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwlchan committed Oct 30, 2024
1 parent f14279a commit 4a30c3f
Show file tree
Hide file tree
Showing 7 changed files with 1,317 additions and 1,299 deletions.
17 changes: 15 additions & 2 deletions Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ www.alexwlchan.net {
header @cached {
Cache-Control "public, max-age=31536000"
}

# Add some security headers.
# I test my security headers with https://securityheaders.com/
header {
Expand All @@ -45,7 +45,7 @@ www.alexwlchan.net {
X-Xss-Protection "1; mode=block"
}

# If somebody gets a 404 or 410 error, respond with my custom error pages.
# If somebody gets a 4xx error, respond with my custom error pages.
handle_errors 404 {
root * /home/alexwlchan/repos/alexwlchan.net/_site
rewrite * 404/index.html
Expand All @@ -57,6 +57,19 @@ www.alexwlchan.net {
rewrite * 410/index.html
file_server
}

# If somebody is trying to look for PHP pages on my site, and WordPress
# pages in particular, they probably have nefarious goals.
#
# This is mostly automated bots -- serve them my minimal 400 Bad Request
# error rather than the complete 404 Not Found page.
@spam {
path /.env /index.php /xmlrpc.php /wp-* /blog/wp-* /cms/wp-* /shop/wp-* /site/wp-* /test/wp-* /wordpress/wp-* /wp/wp-* /wp2/wp-* /zb_system/*
}

handle @spam {
respond "400 Bad Request" 400
}

# This is a mini-site that was built separately and I've just uploaded
# the HTML files to my web server.
Expand Down
11 changes: 0 additions & 11 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@
source: "src"
destination: "_site"

include:

# This file is used by Netlify to define redirects. I also use it
# to create the custom 404 page.
#
# Jekyll ignores files that start with an underscore, so I need to
# include this explicitly.
#
# See https://docs.netlify.com/routing/redirects/
- "_redirects"

# =====================
# Build command options
# =====================
Expand Down
114 changes: 114 additions & 0 deletions caddy/gone.Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
handle /analytics/a.js {
error 410
}

handle /theme/style-sample {
error 410
}

handle /images/talks/oxford_git.jpg {
error 410
}

handle /images/talks/suspicious_minds.jpg {
error 410
}

handle /images/talks/worst_intent.png {
error 410
}

handle /projects/ {
error 410
}





# == Posts which I've removed == #

# I took this post down in June 2023
handle /2019/removing-the-drm-from-my-kindle-books/ {
error 410
}

handle /2019/08/removing-the-drm-from-my-kindle-books/ {
error 410
}

# I removed these posts because they were short link posts of minimal value

handle /2014/12/war-on-christmas/ {
error 410
}

handle /2014/war-on-christmas/ {
error 410
}

handle /2015/01/bbfc-podcast/ {
error 410
}

handle /2015/bbfc-podcast/ {
error 410
}

handle /2015/01/govuk/ {
error 410
}

handle /2015/govuk/ {
error 410
}

handle /2015/01/kings-cross-problems/ {
error 410
}

handle /2015/kings-cross-problems/ {
error 410
}







# == Files which I've removed == #

handle /files/boiler_instructions.pdf {
error 410
}

handle /files/colossus.pdf {
error 410
}

handle /files/ga-privacy.txt {
error 410
}

handle /files/rock-crushers.txt {
error 410
}

handle /talks/campug_git.pdf {
error 410
}

handle /talks/colossus_operators.jpg {
error 410
}

handle /talks/hypothesis_cover.png {
error 410
}

handle /talks/pyconuk2016_cover.png {
error 410
}

# == #
1,187 changes: 1,187 additions & 0 deletions caddy/redirects.Caddyfile

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions src/400.md

This file was deleted.

Loading

0 comments on commit 4a30c3f

Please sign in to comment.