Rewrite a single page from /now to an index.html

1. Caddy version (caddy version):


2. How I run Caddy:

I run Caddy with the Docker image:

FROM klakegg/hugo:0.74.3-alpine AS hugo

COPY blog /src

RUN hugo

FROM caddy:2-alpine

COPY Caddyfile /etc/caddy/Caddyfile
COPY static /site
COPY --from=hugo /src/public /site/blog

a. System environment:


b. Command:

Default Docker RUN command.

c. Service/unit/compose file:

Deployed on GCP Cloud Run.

        gcloud run deploy "$SERVICE_NAME" \
          --quiet \
          --region "$RUN_REGION" \
          --image "$PROJECT_ID/$SERVICE_NAME:$GITHUB_SHA" \
          --platform "managed" \

d. My complete Caddyfile or JSON config:

  http_port {$PORT}
  auto_https off

:{$PORT} {
  root * /site

  try_files {path} {path}/
  rewrite /now /blog/now

  encode zstd gzip

  log {
    output stdout

  header Cache-Control max-age=3600

  header {
    # disable clients from sniffing the media type
    X-Content-Type-Options nosniff
    # clickjacking protection
    X-Frame-Options DENY

    # keep referrer data off of HTTP connections
    Referrer-Policy no-referrer-when-downgrade

  @redir_hosts {
  redir @redir_hosts{uri}

:8888 {
  respond / 200
  log {
    output discard

3. The problem I’m having:

I’m attempting to redirect https://www.julianvmodesto/now internally to /site/blog/now/index.html.

4. Error messages and/or full log output:


5. What I already tried:

I’ve tried reordering my rewrite directive higher up and lower down, and I’ve also tried using the handle directive to serve exactly the file /site/blog/now/index.html or /blog/now/index.html.

6. Links to relevant resources:


1 Like

Hmm. Turn on the debug global option, your logs should show you more details about what’s going on.

You can try doing rewrite /now /blog/now/index.html as well


This topic was automatically closed after 30 days. New replies are no longer allowed.