File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { NextRequest , NextResponse } from 'next/server' ;
2+
3+ const CANONICAL = 'https://c0upons.com' ;
4+
5+ export function middleware ( req : NextRequest ) {
6+ const host = req . headers . get ( 'host' ) ?? '' ;
7+ const proto = req . headers . get ( 'x-forwarded-proto' ) ?? 'https' ;
8+
9+ // Strip www
10+ const isWww = host . startsWith ( 'www.' ) ;
11+ // Redirect railway temp domain to canonical
12+ const isRailway = host . endsWith ( '.railway.app' ) || host . endsWith ( '.up.railway.app' ) ;
13+ // Redirect plain http to https (in case Railway forwards it)
14+ const isHttp = proto === 'http' ;
15+
16+ if ( isWww || isRailway || isHttp ) {
17+ const url = req . nextUrl . clone ( ) ;
18+ url . protocol = 'https' ;
19+ url . host = 'c0upons.com' ;
20+ url . port = '' ;
21+ return NextResponse . redirect ( url , { status : 301 } ) ;
22+ }
23+
24+ return NextResponse . next ( ) ;
25+ }
26+
27+ export const config = {
28+ matcher : [
29+ '/((?!_next/static|_next/image|favicon\\.svg|favicon\\.ico|.*\\.png|.*\\.svg|.*\\.jpg|.*\\.webp).*)' ,
30+ ] ,
31+ } ;
You can’t perform that action at this time.
0 commit comments