Mediawiki in Caddy

I decided I wanted to keep the /w in the URL so that external links to the page do not break. So the URL should look like https://wikidev.tnonline.net/w/Main_Page except for direct usage of files in /mediawiki/ as they should be served as is.

# ll /var/www/domains/wikidev.tnonline.net/htdocs/
total 1080
drwxr-xr-x 1 wiki   apache    430 15 sep 10.02 ./
drwxr-xr-x 1 apache apache     68 15 sep 10.02 ../
-rw-r--r-- 1 wiki   apache  67646  7 jul  2020 favicon.ico
-rw-r--r-- 1 wiki   apache      0 17 jul  2020 index.html
drwxr-xr-x 1 wiki   apache    692 30 maj 09.39 mediawiki/
-rw-r--r-- 1 wiki   apache    210  4 jul 00.49 robots.txt
-rw-r--r-- 1 wiki   apache    647 14 sep 18.20 sitemap-index-my_wiki.xml
-rw-r--r-- 1 wiki   apache   9702 14 sep 18.20 sitemap-my_wiki-NS_0-0.xml
-rw-r--r-- 1 wiki   apache    955 14 sep 18.20 sitemap-my_wiki-NS_14-0.xml
-rw-r--r-- 1 wiki   apache    899 14 sep 18.20 sitemap-my_wiki-NS_4-0.xml
-rw-r--r-- 1 wiki   apache   9741 14 sep 18.20 sitemap-my_wiki-NS_6-0.xml
lrwxrwxrwx 1 wiki   apache     25 14 sep 18.20 sitemap.xml -> sitemap-index-my_wiki.xml
# ll /var/www/domains/wikidev.tnonline.net/htdocs/mediawiki/
total 1584
drwxr-xr-x 1 wiki apache     692 30 maj 09.39 ./
drwxr-xr-x 1 wiki apache     430 15 sep 10.02 ../
-rw-r--r-- 1 wiki apache    4490  8 apr 23.39 api.php
-rw-r--r-- 1 wiki apache  156893 27 maj 20.45 autoload.php
drwxr-xr-x 1 wiki apache      18 30 maj 09.37 cache/
-rw-r--r-- 1 wiki apache     168  8 apr 23.39 CODE_OF_CONDUCT.md
-rw-r--r-- 1 wiki apache    5074 27 maj 20.45 composer.json
-rw-r--r-- 1 wiki apache     102  4 nov  2019 composer.local.json-sample
-rw-r--r-- 1 wiki apache   19421  4 nov  2019 COPYING
-rw-r--r-- 1 wiki apache   13612 27 maj 20.45 CREDITS
drwxr-xr-x 1 wiki apache    1010 30 maj 09.37 docs/
drwxr-xr-x 1 wiki apache     858 18 aug 05.54 extensions/
-rw-r--r-- 1 wiki apache      95  4 nov  2019 FAQ
-rw-r--r-- 1 wiki apache 1247893 27 maj 20.45 HISTORY
drwxr-xr-x 1 wiki apache     122 11 apr 10.50 images/
-rw-r--r-- 1 wiki apache    8245  8 apr 23.39 img_auth.php
drwxr-xr-x 1 wiki apache    3966 30 maj 09.37 includes/
-rw-r--r-- 1 wiki apache    1977  8 apr 23.39 index.php
-rw-r--r-- 1 wiki apache    3612 27 maj 20.45 INSTALL
-rw-r--r-- 1 wiki apache    1430 27 maj 20.45 jsduck.json
drwxr-xr-x 1 wiki apache      88 30 maj 09.37 languages/
-rw-r--r-- 1 wiki apache    1951 27 maj 20.45 load.php
-rwxr--r-- 1 wiki apache    9683 17 sep 11.54 LocalSettings.php*
drwxr-xr-x 1 wiki apache    7988 30 maj 09.48 maintenance/
drwxr-xr-x 1 wiki apache     112 30 maj 09.37 mw-config/
-rw-r--r-- 1 wiki apache    4610  8 apr 23.39 opensearch_desc.php
-rw-r--r-- 1 wiki apache    1525  8 apr 23.39 README.md
-rw-r--r-- 1 wiki apache   45495 27 maj 20.49 RELEASE-NOTES-1.36
drwxr-xr-x 1 wiki apache      50 30 maj 09.37 resources/
-rw-r--r-- 1 wiki apache     998  8 apr 23.39 rest.php
-rw-r--r-- 1 wiki apache     199  4 nov  2019 SECURITY
drwxr-xr-x 1 wiki apache      56 12 aug 16.18 skins/
drwxr-xr-x 1 wiki apache     126 30 maj 09.37 tests/
-rw-r--r-- 1 wiki apache    1439  8 apr 23.39 thumb_handler.php
-rw-r--r-- 1 wiki apache   23581  8 apr 23.39 thumb.php
-rw-r--r-- 1 wiki apache    4544 27 maj 20.45 UPGRADE
drwxr-xr-x 1 wiki apache     380 30 maj 09.37 vendor/

It looks like the problem is still in the rewrite rule/paths. Looking at the debug log we see that it rewrites requests to /mediawiki/rest.php to /mediawiki/index.php?title=...

2021/09/18 07:56:09.990 DEBUG   http.handlers.rewrite   rewrote request
{"request":
	{"remote_addr": "[2001:470:28:704::100]:55312", 
		"proto": "HTTP/2.0", 
		"method": "GET", 
		"host": "wikidev.tnonline.net", 
		"uri": "/mediawiki/rest.php/wikidev.tnonline.net/v3/page/html/Main_Page/1056?redirect=false&stash=true", 
		"headers": {"Content-Length": ["0"], 
			"Accept": ["text/html; charset=utf-8; profile=\"https://www.mediawiki.org/wiki/Specs/HTML/2.0.0\""], 
			"Accept-Language": ["en-gb"], 
			"User-Agent": ["VisualEditor-MediaWiki/1.36.0"], 
			"Api-User-Agent": ["VisualEditor-MediaWiki/1.36.0"], 
			"Promise-Non-Write-Api-Action": ["true"]
			}, 
		"tls": {"resumed": false, 
			"version": 772, 
			"cipher_suite": 4865, 
			"proto": "h2", 
			"proto_mutual": true, 
			"server_name": "wikidev.tnonline.net"
			}
		}, 
	"method": "GET", 
	"uri": "/mediawiki/index.php?title=mediawiki%2Frest.php%2Fwikidev.tnonline.net%2Fv3%2Fpage%2Fhtml%2FMain_Page%2F1056&redirect=false&stash=true"
}