MediaWiki Apache Rewrite Conversion

I am moving my MediaWiki installation from Apache to Caddy and have a .htaccess file that contains some rewrite rules. I have no idea where to even start to convert it to Caddyfile format. Please help!

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/index.php [L]

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&width=$2 [L,QSA,B]

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&width=$2&archived=1 [L,QSA,B]

Bump.

What is this code doing?
How can it be implemented in Caddyfile format.

You can take a look at the relevant Apache documentation to understand those rewrite rules.

The equivalent Caddy rewrite directive can be found here - you should be able to convert the RewriteRule simply enough. I don’t believe it is possible to replicate those rewrite conditions in a Caddyfile, though.

Assuming you’re converting to Caddy for the automatic TLS, consider implementing it as a reverse proxy instead and leaving your Apache server running in order to take advantage of the complex rewrite conditions.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.