---
title: "Deploy Caddy Redirects"
description: "Domain and URL redirects over HTTPS with Caddy redir"
category: "Starters"
url: https://railway.com/deploy/deploy-caddy-redirect-server
---

# Deploy Caddy Redirects

Domain and URL redirects over HTTPS with Caddy redir

**[Deploy Caddy Redirects on Railway](https://railway.com/template/deploy-caddy-redirect-server)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/deploy-caddy-redirect-server/manifest.json

- **Creator:** onepush
- **Category:** Starters

## Template content

### caddy https://github.com/caddyserver.png

- **Image:** ghcr.io/onepush-dev/caddy:2.11.7
- **Health check:** /
- **Public domain:** Yes

## Documentation

# Deploy and Host self hosted Caddy Redirects (Web Redirect Service Configuration) on Railway

Caddy Redirects runs Caddy 2.11.7 as a redirect service on Railway. Old domains can point at the same service.

## About Hosting Caddy Redirects open-source software on Railway (self hosted Caddy redir and map directives for self-hosted redirects template)

Your redirect rules live in a Caddyfile you control, running on Caddy 2.11.7 in your own Railway project.

This template runs one caddy service with redir lines for path moves and an optional map block for bulk tables.

## Why Deploy Caddy Redirects, the Nginx alternative on Railway (Railway Free Trial)

Against Nginx, you trade hands-on control for less upkeep. Railway's $5 trial covers testing your first rules.

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Caddy Redirects on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

### Railway vs Other Hosting Providers and VPS for Caddy Redirects self hosting

Caddy Redirects on Railway keeps your redir and map rules in a Caddyfile you control, without running the host yourself. Here is how that compares.

| Provider | What You Get with Railway | What You Get with the Other Provider |
| --- | --- | --- |
| DigitalOcean | A deployed caddy service with PORT injected and no server to patch. Redirect changes ship by redeploying. | A Droplet with root access, where you install, update and firewall Caddy yourself. |
| AWS | One service on usage billing, with no VPC or load balancer to set up before your first 301 fires. | Deep networking and scaling control, but EC2 or ECS, a load balancer and certificates come first. |
| Hetzner | A managed deployment with a public URL in minutes, so you can check curl -I output right away. | Cheap raw servers with generous bandwidth, but you run the OS, Caddy and renewals. |

Choose a VPS if you need to tune the host itself, and Railway if you mostly want your redirect table running with less upkeep.

## Common Use Cases for hosted Caddy Redirects

Most people deploy Caddy Redirects when a URL change would otherwise break links, rankings, or API clients.

- **Moving a site to a new domain:** Use redir https://new.example.com{uri} permanent. The {uri} placeholder carries the path and query string across.

- **Retiring old pages with permanent 301s:** Permanent codes tell browsers and crawlers to update their records. Keep 302s for maintenance windows, since clients may cache a 301 for a long time.

- **Preserving method on POST endpoints:** Temporary and permanent codes can make clients switch POST to GET. Use 307 or 308 when a legacy form endpoint moved and the method must survive.

- **Bulk-redirecting a legacy URL table:** Define old paths in a map block keyed on {uri}, then feed the output into redir {placeholder}. Spot-check a few rows with curl -I first.

- **Consolidating old hostnames:** Several legacy hostnames can redirect to one canonical Railway domain. Confirm each old domain returns the expected Location header.

## Dependencies for Caddy Redirects Docker hosted on Railway

Caddy Redirects runs as one Docker service on Railway, and the rules live in a Caddyfile in the repo. No database or backing service is needed.

### Deployment Dependencies for Managed Caddy Redirects Service (Web Server)

The service uses the official Caddy 2.11.7 image, wrapped as `ghcr.io/onepush-dev/caddy:2.11.7`, which sits on `caddy:2.11.7-alpine`.

### Implementation Details for Caddy Redirects (Using Caddy official docker image)

There are two variables: `caddy.PORT`, set by Railway, and the optional `caddy.UPSTREAM`.

## How does Caddy Redirects compare against other ways to set up HTTP redirects with Caddy, Nginx, Cloudflare, Netlify and Apache

### Caddy Redirects vs Nginx (Nginx Alternative)

- **Config style:** Caddy uses a redir line such as redir https://example.com{uri} permanent, which reads closer to a sentence than an Nginx return block.
- **Path preservation:** Appending {uri} carries the path and query over, where Nginx often needs explicit $request_uri handling.
- **Where Nginx wins:** If your team already runs Nginx with mature rules, moving redirects adds migration cost with no clear gain.

### Caddy Redirects vs Cloudflare Redirect Rules (Edge Redirects)

- **Where redirects run:** Caddy Redirects runs on your own Railway service, so every rule lives in a Caddyfile you version yourself.
- **Bulk tables:** A map block feeding redir {placeholder} keeps a legacy URL table in your repo rather than a dashboard.
- **Where Cloudflare wins:** Its edge redirects fire before traffic reaches your origin and are quicker to set up for a domain already proxied there.

### Caddy Redirects vs Netlify redirects (Netlify Alternative)

- **Declaration file:** Netlify reads a _redirects file or netlify.toml, while Caddy reads a Caddyfile that also handles reverse proxying.
- **Hosting coupling:** Netlify redirects only apply to sites hosted on Netlify, whereas this service fronts any domain you attach through Railway networking.
- **Where Netlify wins:** For a site already on Netlify, its redirect file is the shortest path and needs no extra service.

### Caddy Redirects vs Apache mod_rewrite (Apache Alternative)

- **Rule model:** mod_rewrite uses RewriteRule patterns and flags, while redir takes a target plus an optional code such as permanent or temporary.
- **Status codes:** You pick 301, 302, 307 or 308 explicitly, so POST endpoints can keep their HTTP method without guessing at flag combinations.
- **Where Apache wins:** Its .htaccess handling and existing rulesets on shared hosting are established, and Caddy does not try to replace them.

## How to use Caddy Redirects (the OSS web server and reverse proxy)?

1. Deploy the caddy service on Railway and confirm PORT is injected.
2. Optionally set caddy.UPSTREAM to host:port for reverse-proxy mode. Leave it empty to serve static files from /srv.
3. Add a site block with a whole-domain redir. Use permanent (301) for a final move:

```
http://example-old.com:{$PORT} {
    redir https://example.com{uri} permanent
}
```

4. For path-to-path moves, add a redir inside the site block, such as redir /about-us /about.
5. For bulk moves, key a map block on {uri} and redirect to the mapped placeholder:

```
http://example.com:{$PORT} {
    map {uri} {new_path} {
        /old-page /new-page
        default -
    }
    @moved not {new_path} -
    redir @moved {new_path} permanent
}
```

6. Attach your custom domain through Railway networking. Old domains need their own DNS steps.
7. Test each rule with curl -I against the deployed URL. Check the status line and the Location header.

## How to self host Caddy Redirects on other VPS Services (Caddy self hosting guide)

Caddy ships as one binary, so a Linux VPS with Docker is enough. These steps match the Railway template.

### Clone the Repository

Pull the project onto your server and move into it.

```
git clone https://github.com/onepush-dev/caddy.git
cd caddy
```

### Install Dependencies

Docker and Docker Compose are the only host requirements, since Caddy lives inside the official image.

```
docker --version
docker compose version
```

### Configure Environment Variables

Set PORT for the listen port and leave UPSTREAM empty for pure redirect mode.

```
PORT=8080
UPSTREAM=
```

Add one redir line per old address in the Caddyfile. Keep {uri} so paths carry over.

```
your-domain {
    redir https://new-domain.example{uri} permanent
}
```

### Start the Caddy Redirects Application

Start the service, then confirm the status line and Location header with curl -I.

```
docker compose up -d
curl -I http://localhost:8080/old-page
```

Railway would otherwise handle TLS, the public domain, and restarts for you, and on a VPS you wire those up yourself.

## Official Pricing of Caddy Redirects (Caddy pricing)

Caddy itself is free and open source under the Apache-2.0 license, so there is no license fee to pay for the redirect service.

## Caddy Redirects cloud vs self hosted comparison (Pricing, features, costs, and more)

Self hosting Caddy Redirects means you own every 301, 302, 307 and 308 in your Caddyfile, and the cost question comes down to one small always-on service.

### Monthly cost of self hosting Caddy Redirects on Railway

A single Caddy service at light traffic is typically a few dollars a month on Railway usage pricing, and Railway offers a $5 trial to start.

### System Requirements for Hosting Caddy Redirects on a VPS

A redirect-only workload runs fine on a small VPS with a few hundred megabytes of free memory and a modern Linux kernel.

## Frequently Asked Questions (FAQs)

### Should I use 301 or 302 for a temporary move?

Use 302 (temporary) when the move is only temporary, so clients keep the original URL in play.

### When do I need 307 or 308 to keep the HTTP method?

Use 307 or 308 when the method must survive the redirect, such as a POST to a legacy endpoint.

### How do I keep the path and query when redirecting to a new domain?

Append the {uri} placeholder to the target, for example redir https://example.com{uri} permanent.

### How do I redirect a whole table of old paths?

Use a map block keyed on {uri} to set a placeholder for each old path, then point redir at that placeholder. Each row becomes one input-output pair.

### Why does my redirect not fire before other directives?

The redir directive runs very early in Caddy's directive order, so a matched request is answered before later directives run.

### How do I verify the redirect with curl -I?

Run curl -I against the deployed URL and read the status line and the Location header.


## Similar templates

- [Openfront Gym](https://railway.com/deploy/openfront-gym) — Opensource Mindbody alternative based on Next.js and Keystone.js
- [open-excalidraw](https://railway.com/deploy/open-excalidraw) — Self-hostable collaborative drawing built on Excalidraw
- [Next.js + Prisma + PostgreSQL Starter](https://railway.com/deploy/nextjs-prisma-postgres) — Deploy a Next.js app with Prisma ORM and PostgreSQL in one click.

Open this page in a browser: https://railway.com/deploy/deploy-caddy-redirect-server
