How to Configure Windows Sandbox Local Traefik AddPrefix Middleware via XML in Windows 11

Routing requests to backend microservices that expect internal root prefixes (such as prepending /internal/v1 to incoming public root requests) requires dynamic URL rewriting. Traefik’s AddPrefix middleware prepends a defined path prefix to incoming request URIs before forwarding them downstream. Windows Sandbox on Windows 11 provides a secure, disposable container for validating path prefix injection safely.

Why Test AddPrefix in Windows Sandbox

Misconfigured path rewrites can result in 404 routing errors or unintended backend loopbacks. Testing inside an isolated Windows Sandbox allows engineers to test prefix rewriting logic against mock upstream services without altering host machine network configurations.

Authoring the Windows Sandbox WSB XML

Save the following XML document as TraefikAddPrefixSandbox.wsb on your Windows 11 machine:

<Configuration>
  <VGpu>Default</VGpu>
  <Networking>Default</Networking>
  <MappedFolders>
    <MappedFolder>
      <HostFolder>C:\TraefikAddPrefixLab</HostFolder>
      <SandboxFolder>C:\TraefikAddPrefixLab</SandboxFolder>
      <ReadOnly>true</ReadOnly>
    </MappedFolder>
  </MappedFolders>
  <LogonCommand>
    <Command>powershell.exe -ExecutionPolicy Bypass -NoExit -File C:\TraefikAddPrefixLab\setup-addprefix.ps1</Command>
  </LogonCommand>
</Configuration>

PowerShell Deployment Bootstrapper

Save the bootstrapping script as C:TraefikAddPrefixLabsetup-addprefix.ps1:

Write-Host "Setting up Traefik AddPrefix Lab..." -ForegroundColor Cyan

$Dir = "C:Traefik"
New-Item -ItemType Directory -Force -Path $Dir | Out-Null

$ZipUrl = "https://github.com/traefik/traefik/releases/download/v3.0.0/traefik_v3.0.0_windows_amd64.zip"
Invoke-WebRequest -Uri $ZipUrl -OutFile "$Dir	raefik.zip"
Expand-Archive -Path "$Dir	raefik.zip" -DestinationPath $Dir -Force

$Config = @"
http:
  middlewares:
    inject-prefix:
      addPrefix:
        prefix: "/api/v1"
  routers:
    public-router:
      rule: "PathPrefix(`/users`)"
      middlewares:
        - "inject-prefix"
      service: "backend-service"
  services:
    backend-service:
      loadBalancer:
        servers:
          - url: "http://127.0.0.1:8080"
"@

Set-Content -Path "$Dirdynamic_conf.yml" -Value $Config
Write-Host "Traefik AddPrefix Middleware Configured for /api/v1 Prepends." -ForegroundColor Green

Verifying Prefix Injection

Launch the sandbox configuration and run curl requests against http://127.0.0.1/users. Verify that the backend receives the rewritten path /api/v1/users. Closing the sandbox leaves no residual configuration files.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.