# Error: Server Actions cannot redirect to external URLs. Use NextResponse.redirect() instead.

- **ID:** `nextjs/server-action-redirect-external`
- **Domain:** nextjs
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

Server Actions use the 'use server' directive and can only redirect to internal routes using redirect(). External URLs require a different approach, such as NextResponse.redirect() in middleware or a client-side redirect.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| next@14.2.0 | active | — | — |
| next@15.0.0 | active | — | — |

## Workarounds

1. **Return a redirect URL from the Server Action and handle the redirect on the client side using useRouter or window.location.** (90% success)
   ```
   Return a redirect URL from the Server Action and handle the redirect on the client side using useRouter or window.location.
   ```
2. **Use NextResponse.redirect() in middleware with a custom header set by the Server Action.** (80% success)
   ```
   Use NextResponse.redirect() in middleware with a custom header set by the Server Action.
   ```

## Dead Ends

- **** — Server Actions run on the server; window is not defined, causing a ReferenceError. (95% fail)
- **** — This adds complexity and may not work with Next.js error boundaries, leading to unhandled rejections. (70% fail)
