LVLogo

Old Blog/Page rewrite rules -> new server on automad

2026-11-17 — Thomas Raschbacher (LordVan)

So to keep the old URLS working when i shut down mezzanine I added rewriterules and a little testscript (with some assistance to fix bugs from gemini to be fair):

<VirtualHost *:443>
    ServerName blog.lordvan.com
    # ... SSL config, document root if needed,..
    #DocumentRoot /var/www/empty
    #<Directory /var/www/empty>
    #    AllowOverride FileInfo
    #    Require all granted
    #</Directory>

    RewriteEngine On

    # 1. Exact root redirect (https://blog.lordvan.com/ -> https://www.lordvan.com/)
    RewriteRule ^/$ https://www.lordvan.com/ [R=301,L]

    # 2. Section prefix redirects
    # Matches /about, /about/, /about/history/, /about/team/ -> /about
    RewriteRule ^/about(/.*)?$ https://www.lordvan.com/about [R=301,L]

    # Matches /dev, /dev/, /dev/anything -> /projects
    RewriteRule ^/dev(/.*)?$ https://www.lordvan.com/projects [R=301,L]

    # blog exceptions due to umlauts, underscores and too long slugs    
    RewriteRule ^/blog/small-script-to-find-duplicate-contact_mechanisms-for-parties-in-tryton/?$ https://www.lordvan.com/blog/small-script-to-find-duplicate-contact-mechanisms-for-parties-in-tryton [R=301,L]
    RewriteRule ^/blog/gui-and-trytond_import_countriescurrencies-gives-trytondmodelmodelstorageselectionvalidationerror/?$ https://www.lordvan.com/blog/gui-and-trytond-import-countriescurrencies-gives-trytondmodelmodelstorageselectionvalidationerror [R=301,L]
    RewriteRule ^/blog/django-mod_wsgi-apache-bad-request-400/?$ https://www.lordvan.com/blog/django-mod-wsgi-apache-bad-request-400 [R=301,L]
    RewriteRule ^/blog/apache-mod_wsgi-django-rest-framework-resteasy/?$ https://www.lordvan.com/blog/apache-mod-wsgi-django-rest-framework-resteasy [R=301,L]
    RewriteRule ^/blog/basic-small-web-application-with-mod_wsgi-and-python/?$ https://www.lordvan.com/blog/basic-small-web-application-with-mod-wsgi-and-python [R=301,L]
    RewriteRule ^/blog/mezzanine-with-mod_wsgi-on-apache-on-gentoo/?$ https://www.lordvan.com/blog/mezzanine-with-mod-wsgi-on-apache-on-gentoo [R=301,L]
    RewriteRule ^/blog/a-little-useful-addition-for-ssh-login-from-putty-to-my-bashrc-bash_profile/?$ https://www.lordvan.com/blog/a-little-useful-addition-for-ssh-login-from-putty-to-my-bashrc-bash-profile [R=301,L]
    RewriteRule ^/blog/comic-und-figurenbörse-wow-being-pita/?$ https://www.lordvan.com/blog/comic-und-figurenboerse-wow-being-pita [R=301,L]
    RewriteRule ^/blog/solid-edge-formelemente-unterdrücken-UEber-variablentabelle/?$ https://www.lordvan.com/blog/solid-edge-formelemente-unterdruecken-ueber-variablentabelle [R=301,L]
    RewriteRule ^/blog/windows-active-directory-gpo-hinzufügen-und-zuweisen/?$ https://www.lordvan.com/blog/windows-active-directory-gpo-hinzufuegen-und-zuweisen [R=301,L]
    RewriteRule ^/blog/busy-weekend-birthday-party-galactic-friendship-meeting-comicfiguren-börse/?$ https://www.lordvan.com/blog/busy-weekend-birthday-party-galactic-friendship-meeting-comicfiguren-boerse [R=301,L]

    # this one was just too long for automad
    RewriteRule ^blog/leonard-nimoy-im-krankenhaus-erholt-sich-gut-nach-not-op-leonard-nimoy-in-hospital-recovering-beautifully/?$ https://www.lordvan.com/blog/leonard-nimoy-im-krankenhaus-erholt-sich-gut-nach-not-op-leonard-nimoy-in-hospital-recovering-beauti [R=301,L]


    # 3. Blog posts & blog index (/blog/ and /blog/slug/ -> /blog and /blog/slug)
    RewriteRule ^/blog/?$ https://www.lordvan.com/blog [R=301,L]
    RewriteRule ^/blog/(.*?)/?$ https://www.lordvan.com/blog/$1 [R=301,L]
</VirtualHost>

And a little bash script to test if it works:

#!/bin/sh

grep slug *.json | cut -d':' -f2 | cut -d'"' -f2 | while read -r slug; do
  # Strip any accidental leading/trailing slashes
  slug="${slug#/}"; slug="${slug%/}"
  
  # Check 301 target and final 200 status in one go
  res=$(curl -s -L -o /dev/null -w "%{http_code} %{url_effective}" "https://blog.lordvan.com/blog/${slug}/")
  
  if [[ "$res" != "200 https://www.lordvan.com/blog/${slug}" ]]; then
    echo "[FAIL] ${slug} -> ${res}"
  # else
  #     echo "[OK] ${slug} -> ${res}"
  fi
done

Just one thing to keep in mind - and I didn'T fix it cuz I am lazy and well it was only a few.. it says [FAIL] for the special cases because the url/slug is different -- even though it is HTTP/1.1 200 OK .. so it gave me this (which is fine):

# sh test_redirects.sh 
[FAIL] small-script-to-find-duplicate-contact_mechanisms-for-parties-in-tryton -> 200 https://www.lordvan.com/blog/small-script-to-find-duplicate-contact-mechanisms-for-parties-in-tryton
[FAIL] gui-and-trytond_import_countriescurrencies-gives-trytondmodelmodelstorageselectionvalidationerror -> 200 https://www.lordvan.com/blog/gui-and-trytond-import-countriescurrencies-gives-trytondmodelmodelstorageselectionvalidationerror
[FAIL] django-mod_wsgi-apache-bad-request-400 -> 200 https://www.lordvan.com/blog/django-mod-wsgi-apache-bad-request-400
[FAIL] solid-edge-formelemente-unterdrücken-über-variablentabelle -> 200 https://www.lordvan.com/blog/solid-edge-formelemente-unterdruecken-ueber-variablentabelle
[FAIL] apache-mod_wsgi-django-rest-framework-resteasy -> 200 https://www.lordvan.com/blog/apache-mod-wsgi-django-rest-framework-resteasy
[FAIL] basic-small-web-application-with-mod_wsgi-and-python -> 200 https://www.lordvan.com/blog/basic-small-web-application-with-mod-wsgi-and-python
[FAIL] windows-active-directory-gpo-hinzufügen-und-zuweisen -> 200 https://www.lordvan.com/blog/windows-active-directory-gpo-hinzufuegen-und-zuweisen
[FAIL] mezzanine-with-mod_wsgi-on-apache-on-gentoo -> 200 https://www.lordvan.com/blog/mezzanine-with-mod-wsgi-on-apache-on-gentoo
[FAIL] a-little-useful-addition-for-ssh-login-from-putty-to-my-bashrc-bash_profile -> 200 https://www.lordvan.com/blog/a-little-useful-addition-for-ssh-login-from-putty-to-my-bashrc-bash-profile
[FAIL] leonard-nimoy-im-krankenhaus-erholt-sich-gut-nach-not-op-leonard-nimoy-in-hospital-recovering-beautifully -> 200 https://www.lordvan.com/blog/leonard-nimoy-im-krankenhaus-erholt-sich-gut-nach-not-op-leonard-nimoy-in-hospital-recovering-beauti
[FAIL] busy-weekend-birthday-party-galactic-friendship-meeting-comicfiguren-börse -> 200 https://www.lordvan.com/blog/busy-weekend-birthday-party-galactic-friendship-meeting-comicfiguren-boerse
[FAIL] comic-und-figurenbörse-wow-being-pita -> 200 https://www.lordvan.com/blog/comic-und-figurenboerse-wow-being-pita

Now I can finally remove some older python version this was running on (virtualenv fun with mod_wsgi [which will also go bye-bye .. in the future I will only run my django/python stuff on gunicorn or similar to avoid these headaches]).

Blog XMPP .. anyone else still using it?