If your website is deployed on Vercel but your domain DNS and email still live at SiteGround, Hostinger, or another shared host, this issue is common:
You click Webmail Login in the hosting dashboard, the host sends you through a tokenized webmail path on your own domain, and then your Next.js app returns 404.
This happened in production, and the fix below works reliably with App Router and Vercel deployments.
The Real Objective
The target setup was:
- Website hosting on Vercel
- Email hosting at SiteGround (or similar)
- root and nested webmail paths always redirecting to the provider webmail endpoint
- Tokenized URLs preserved so dashboard auto-login flows keep working
If you only redirect the simplest shortcut and ignore deeper provider-generated paths with query strings, you still break real users.
Why the 404 Happens
When your domain points to Vercel via A/CNAME, Vercel is the web server for all paths on that domain.
That means these requests are now handled by your Next.js app too:
- the plain webmail shortcut
- nested mailbox login paths
- provider-generated webmail links with query strings
If App Router has no matching route for those paths, the 404 is expected behavior.
If you're rebuilding legacy stacks, this pattern appears often during WordPress to Next.js migrations.
Why the First Fixes Usually Fail
Config-only Redirect For One Path
This is the first thing most people try. It handles one path, but tokenized links often use deeper paths generated by your hosting panel.
Middleware for everything
Middleware can work, but for this exact use case it is more moving parts than you need. An App Router-native route handler is usually cleaner.
Forgetting query-string preservation
If the redirect drops the provider query string, the user gets bounced to a login screen instead of auto-login.
Production Fix: App Router Routing + Catch-All Coverage
Create coverage for the root webmail shortcut and every nested webmail path. The catch-all behavior matters because hosting dashboards often generate deeper tokenized paths rather than a plain shortcut.
Step 1: Handle the Root Shortcut
The root handler should redirect to the provider's webmail host with a temporary method-preserving redirect. Keep the provider base URL in configuration, not inline in public documentation or scattered across routes.
Step 2: Handle Nested Login Paths and Preserve Query Params
The nested handler should forward the remaining path and preserve the original query string. That is what keeps provider auto-login tokens intact without logging or exposing the token value in your own content.
Why This Works
- the root webmail shortcut is caught
- every nested webmail path is caught
- query strings are forwarded unchanged
- deployment stays fully compatible with Vercel edge runtime
So both the root webmail link and tokenized nested links work without creating Next.js pages for email hosting.
Quick Deployment Checklist
- You are on App Router
- Both root and catch-all route handlers exist
- Your configured destination points to your provider's real webmail host
- You redeployed Vercel after adding handlers
- You tested from the hosting dashboard login button, not only manual URL entry
Security and Operations Notes
- Do not log token query strings in server logs.
- Keep email infrastructure (MX, SPF, DKIM, DMARC) at your email provider.
- This fix is routing-only; it does not change mail delivery.
Where This Fits in a Migration
In production content, we used this article as a bridge to:
- architecture service pages like Next.js migration services
- implementation support pages like Custom web development
- short-form runbooks in Tutorials
If you want implementation review before launch, start here: Book a strategy call.
FAQ
Does this change MX records or mailbox data?
No. It only changes HTTP routing for webmail shortcut paths.
Should I use 307 or 308?
Use a temporary method-preserving redirect during this kind of operational routing. Keep it explicit and test your provider flow.
Can this work for Hostinger, cPanel, or custom mail hosts?
Yes. Configure your provider endpoint and keep the catch-all routing in place.
Keep the Thread Going
- Service path: Next.js Migrations
- Related read: Fix /webmail 404 on Vercel in 10 Minutes (SiteGround/Hostinger)
- Proof point: Aerconic
- Ready to scope your own version? Start a project




