Routing dynamic API requests with versioned path prefixes (such as /api/v[0-9]+/) often requires stripping regex path patterns before forwarding requests to backend microservices. Traefik’s StripPrefixRegex middleware removes matched regular expressions dynamically from incoming request URIs. Windows Sandbox in Windows 11 provides a secure, disposable container for validating regex path-stripping workflows safely.
Why Test StripPrefixRegex in Windows Sandbox
Flawed regular expressions can inadvertently strip critical URL paths or cause routing misdirections. Testing inside an isolated Windows Sandbox allows engineers to test regex edge cases against mock backends without exposing local development ports.
Authoring the Windows Sandbox WSB XML
Save the following XML document as TraefikRegexSandbox.wsb on your Windows 11 machine:
<Configuration>
<VGpu>Default</VGpu>
<Networking>Default</Networking>
<MappedFolders>
<MappedFolder>
<HostFolder>C:\TraefikRegexLab</HostFolder>
<SandboxFolder>C:\TraefikRegexLab</SandboxFolder>
<ReadOnly>true</ReadOnly>
</MappedFolder>
</MappedFolders>
<LogonCommand>
<Command>powershell.exe -ExecutionPolicy Bypass -NoExit -File C:\TraefikRegexLab\setup-stripregex.ps1</Command>
</LogonCommand>
</Configuration>
PowerShell Deployment Bootstrapper
Save the bootstrapping script as C:TraefikRegexLabsetup-stripregex.ps1:
Write-Host "Setting up Traefik StripPrefixRegex 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:
regex-strip:
stripPrefixRegex:
regex:
- "^/api/v[0-9]+"
routers:
api-router:
rule: "PathPrefix(`/api/v1`, `/api/v2`)"
middlewares:
- "regex-strip"
service: "api-backend"
services:
api-backend:
loadBalancer:
servers:
- url: "http://127.0.0.1:8080"
"@
Set-Content -Path "$Dirdynamic_conf.yml" -Value $Config
Write-Host "Traefik StripPrefixRegex Configured for /api/v[0-9]+." -ForegroundColor Green
Verifying Path Stripping
Launch the sandbox configuration and run curl requests against http://127.0.0.1/api/v1/users. Verify that Traefik strips the version prefix and forwards /users directly to the backend service. Closing the sandbox purges all temporary files cleanly.