1. Caddy version (caddy version
):
v2.4.6 h1:HGkGICFGvyrodcqOOclHKfvJC0qTU7vny/7FhYp9hNw=
2. How I run Caddy:
I have it installed from the apt repo and running it as a service. My /etc/apt/sources.list.d/caddy-stable.list
looks as follows:
# Source: Caddy
# Site: https://github.com/caddyserver/caddy
# Repository: Caddy / stable
# Description: Fast, multi-platform web server with automatic HTTPS
deb https://dl.cloudsmith.io/public/caddy/stable/deb/debian any-version main
deb-src https://dl.cloudsmith.io/public/caddy/stable/deb/debian any-version main
a. System environment:
No Docker. Running it on top of Ubuntu 20.
b. Command:
service caddy start
c. Service/unit/compose file:
Using the default that came from apt.
d. My complete Caddyfile or JSON config:
example.ro {
root * /home/grn/app/public
redir /dev/index.php?id=125&p=1471&s=473001&z=L&c=P http://google.com
redir /dev/index.php?id=125&p=1471&s=473001&z=L&c=F http://google.com{uri}
file_server
@not_static not file
reverse_proxy @not_static 127.0.0.1:3000
encode zstd gzip
log {
output file /var/log/caddy/example.ro.log {
roll_size 100mb
roll_keep 20
roll_keep_for 168h
}
format console
}
}
3. The problem Iâm having:
The redirect DOES NOT work as expected. However, if I change the ? in the URL with & it works.
First, I query the exact URL. I get 404 instead of the redirect, after Caddy hits the Ruby On Rails backend after reverse proxying.
[grn@tayqo:~] $ curl -I 'https://example.ro/dev/index.php?id=125&p=1471&s=473001&z=L&c=P'
HTTP/2 404
content-type: text/html; charset=utf-8
link: </assets/application-53889e48c84d6a2fc3f23c3e659e3656f46ecf7e7195277ae651ee5a68164c91.css>; rel=preload; as=style; nopush,</packs/js/addtohomescreen-654677869d996d871b51.js>; rel=preload; as=script; nopush
referrer-policy: strict-origin-when-cross-origin
server: Caddy
strict-transport-security: max-age=63072000; includeSubDomains
vary: Accept
x-content-type-options: nosniff
x-download-options: noopen
x-frame-options: SAMEORIGIN
x-permitted-cross-domain-policies: none
x-request-id: 69c15562-a3c8-4ece-a0f0-0b0d43242660
x-runtime: 0.005247
x-xss-protection: 0
date: Wed, 09 Feb 2022 15:13:13 GMT
Second, I query the URL I want to but replace the ? with & (or truly any other character). I DO get the redirect that I would expect:
[grn@tayqo:~] $ curl -I 'https://example.ro/dev/index.php&id=125&p=1471&s=473001&z=L&c=P'
HTTP/2 302
location: http://google.com
server: Caddy
date: Wed, 09 Feb 2022 15:13:17 GMT
5. What I already tried:
I tried to escape the question mark, as maybe that gets interpreted as regex. Not working. Went through the docs, looking for things I may have missed. Scoured the internet for articles or blogs. Could not find a fix.
I noticed that if I remove the ? then the new URL would get the proper redirect that I would expect. I also noticed that if I leave the ? in the URL but upon doing a cURL I replace it with a different (any) character, it works. But it never works when I have a ? in the URL and I query that URL.
So, it seems to me that in a redir $from $to
, if the $from
contains a question mark, the redirect is not working properly.
Thoughts?