1. The problem I’m having:
Hi,
First of all sorry if my question seems very simple but I can’t get out of it and I haven’t found a corresponding topic.
I have a symphony project and I want to do an internal redirection from a legacy route which no longer exists (/password/forgot) to another route (/api/users/password/reset).
I was thinking of using the rewrite directive (see my caddy config below) but this does not work if I rewrite to another symfony route. However it works for static files like favicon.ico.
I suppose that the rewrite rule is more complicated to write because of the php_fastcgi.
Could you tell me how to do an internal redirection in my situation?
Thanks a lot
2. Error messages and/or full log output:
> POST https://localhost:4430/password/forgot
Status 404
No route found for "POST https://localhost:4430/password/forgot" (404 Not Found)
> POST https://localhost:4430/api/users/password/reset
Status 204
I want to have
> POST https://localhost:4430/password/forgot
Status 204
3. Caddy version:
v2.6.4 h1:2hwYqiRwk1tf3VruhMpLcYTg+11fCdr8S3jhNAdnPy8=
4. How I installed and ran Caddy:
a. System environment:
Ubuntu 22.04.3 LTS
Docker version 24.0.5, build 24.0.5-0ubuntu1~22.04.1
c. Compose file:
caddy:
build:
context: api/
target: app_caddy
depends_on:
- php
environment:
SERVER_API_NAME: ${SERVER_API_NAME:-localhost}, caddy:80
restart: unless-stopped
volumes:
- php_socket:/var/run/php
- caddy_data:/data
- caddy_config:/config
ports:
# HTTP
- target: 80
published: ${HTTP_PORT:-80}
protocol: tcp
# HTTPS
- target: 443
published: ${HTTPS_PORT:-443}
protocol: tcp
# HTTP/3
- target: 443
published: ${HTTP3_PORT:-443}
protocol: udp
d. My complete Caddy config:
{
# Debug
{$CADDY_DEBUG}
}
{$SERVER_API_NAME} {
log
route {
#rewrite /password/forgot /favicon.ico # This works
rewrite /password/forgot /api/users/password/reset # This not works
root * /srv/app/public
header ?Link `</docs.jsonld>; rel="http://www.w3.org/ns/hydra/core#apiDocumentation"`
header ?Permissions-Policy "browsing-topics=()"
header +Access-Control-Expose-Headers "pagination-current-page, pagination-items-per-page, pagination-total-items"
php_fastcgi unix//var/run/php/php-fpm.sock
encode zstd gzip
file_server
}
}