In the past I published a link http://wiki.passchier.net/index.php?page=Thai+Bible+Translations to a wiki page on a different system. Nowadays, this page is served on wiki.passchier.net through the markdown plugin on Caddy.
I would like to keep the link working by using rewrite but haven’t succeeded – perhaps because the url parameter syntax gets in the way? It just returns a 404.
Also just creating a softlink on the filesystem didn’t work.
To clarify, you had a page at http://wiki.passchier.net/index.php?page=Thai+Bible+Translations and you now want to rewrite requests for this address to a page you’re currently serving via markdown?
What’s the address of the page you want to serve, and what does your Caddyfile look like right now?
The address now is wiki.passchier.net/thaibible.md and I have a softlink pointing to it at index.md so just wiki.passchier.net serves the page.
The Caddyfile: wiki.passchier.net {
root /var/www/caddywiki/
log stdout
errors stderr
minify
gzip
ext .md
markdown {
ext .php
css /wiki.css
js /wiki.js
}
}
(The ext .php I added to solve this problem, together with a softlink index.php to thaibible.md)
When you say “Really needs index.php to be tried”, do you mean that you want it to try index.php for some specific reason? Or do you mean that ext .md isn’t working like I thought?
What dictates the requirement for a reference to index.php? Perhaps I am misunderstanding the function of ext, but with that rewrite, when Caddy gets a request for /, it pretends it was actually a request for /thaibible.md and serves that markdown file instead of any index files at site root. You’ve specified a markdown directive, which by default will process .md files. There should be no need whatsoever for any index files with this method, regardless of extension.
Does thaibible.md actually exist in the site root?
My problem was that I want this link to be serving the wiki page:
It asks for index,php so if it isn’t referenced, the above link won’t lead anywhere.
For the rest the page at http://wiki.passchier.net worked fine as it was.
I had written the page in thaibible.md but then realized I needed index.md. I could have renamed thaibible.md, but instead I made a softlink index.md pointing to it for future extension.
This is what I tried initially. The error log says: [ERROR 500 /index.php] open /var/www/caddywiki/index.php: no such file or directory
Which made me realize I need to make reference to index.php and ignore the other information.
But, this rewrite works: rewrite /index.php /thaibible.md !
It’s probably going to be slightly slower than the filesystem solution, but it will be the Caddy way of solving it.
I’m not sure why rewrite /index.php?page=Thai+Bible+Translations would fail, is that expected behaviour or a bug of some kind?
You could potentially try a workaround, for the sake of specificity:
rewrite /index.php {
if {query} ends_with Thai+Bible+Translations
to /thaibible.md
}
I don’t believe that rewrite /index.php will be measurably slower than a filesystem solution. Think of it as instead of Caddy doing a rewrite, your filesystem is doing a rewrite. My workaround might be a hair’s breadth behind, because of the substring match, but there’s no regex so it should be quite servicable even with a very high workload.
After having thought about it, Caddy would know how URLs work, and to only look for the file part. I’m happy for index.php?anything to be redirected, so I won’t get more restrictive, but that line is a good one. I wonder how far back you can go. Would if {query} ends_with ?page=Thai+Bible+Translations also work? That would be most specific.
It would not work, because {query} does not include the preceding question mark. The absolutely specific version would be if {query} is page=Thai+Bible+Translations, but I would test that before deploying to be certain.