1. The problem I’m having:
I’m considering switching from Apache to Caddy.
I am using Apache to perform the following redirect.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^test.txt$ /test2.txt [R=301,L]
RewriteCond %{REQUEST_URI} (.+[^/])$
RewriteRule ^ %1/ [L,R=301]
</IfModule>
I converted this to Caddyfile, but I don’t know how to interrupt the redirection midway.
In the example below, after being redirected to /test2.txt
, it is redirected to /test2.txt/
.
In the Apache settings, you can specify that no further redirects will be performed with [R=301,L]
, but is there a similar method for Caddy?
I know that I can exclude it with not path
, but there are quite a lot of paths I want to redirect, so I would like to refrain from using it if possible.
Sorry for the confusing question.
2. Error messages and/or full log output:
curl -LI staging.riku22.net/test.txt
HTTP/1.1 308 Permanent Redirect
Connection: close
Location: https://staging.riku22.net/test.txt
Server: Caddy
Date: Wed, 19 Jun 2024 21:30:48 GMT
HTTP/2 301
alt-svc: h3=":443"; ma=2592000
location: /test2.txt
server: Caddy
date: Wed, 19 Jun 2024 21:30:48 GMT
HTTP/2 301
alt-svc: h3=":443"; ma=2592000
location: /test2.txt/
server: Caddy
date: Wed, 19 Jun 2024 21:30:48 GMT
HTTP/2 404
alt-svc: h3=":443"; ma=2592000
server: Caddy
date: Wed, 19 Jun 2024 21:30:48 GMT
3. Caddy version:
v2.8.4 h1:q3pe0wpBj1OcHFZ3n/1nl4V4bxBrYoSoab7rL9BMYNk=
4. How I installed and ran Caddy:
- Installed from official Cloudsmith ubuntu repository
- Domain name:
staging.riku22.net
a. System environment:
Ubuntu 24.04
b. Command:
systemctl start caddy
c. Service/unit/compose file:
Uses official systemd service.
d. My complete Caddy config:
staging.riku22.net {
root * /srv/www/staging.riku22.net
file_server
redir /test.txt /test2.txt 301
add_trailing_slash {
path_regexp (.+[^/])$
}
redir @add_trailing_slash {re.1}/ 301
}