---
title: "Apache RedirectMatch — Suffix-Preserving 301 for Service Deactivation"
tags: [apache, redirect, regex, devops, oliver]
source: daily/2026-05-14.md
created: 2026-05-15
---

# Apache RedirectMatch — Suffix-Preserving 301 for Service Deactivation

## Pattern

When deactivating a path served by `ProxyPass` (e.g., moving a service off a subdomain), replace the entire `ProxyPass + Alias + Directory` block with a single `RedirectMatch`:

```apache
# BEFORE (active service)
ProxyPass /video-accessibility http://localhost:3001/
ProxyPass /video-accessibility/ http://localhost:3001/
Alias /video-accessibility /var/vhosts/.../video-accessibility
<Directory /var/vhosts/.../video-accessibility>
    ...
</Directory>

# AFTER (service moved to optical-dev)
RedirectMatch permanent ^/video-accessibility(/.*)?$ https://optical-dev.oliver.solutions/video-accessibility$1
```

## Key Details

| Part | Meaning |
|------|---------|
| `^/video-accessibility` | Anchor to exact path prefix |
| `(/.*)?` | Capture group 1: optional trailing slash + anything |
| `$` | End of URI |
| `$1` | Append captured suffix to destination URL |

## Why the capture group matters

Without `(/.*)?$1`, deep links break silently:

```
# Without suffix capture:
/video-accessibility/jobs/abc123  →  https://optical-dev.../video-accessibility
#                                    (suffix lost — 404 on destination)

# With suffix capture:
/video-accessibility/jobs/abc123  →  https://optical-dev.../video-accessibility/jobs/abc123
```

## When to use

- Service relocated to a different server/subdomain, but old URLs must keep working
- Deactivating a vhost path without breaking bookmarks or SEO
- Simpler than maintaining a dead ProxyPass target

## Reload

```bash
sudo apachectl configtest && sudo systemctl reload apache2
```

Always run `configtest` first — a regex syntax error silently 500s the entire vhost.
