SEO
This commit is contained in:
@@ -41,9 +41,18 @@ function attachAttributionCookie(req: NextRequest, response: NextResponse) {
|
||||
return response;
|
||||
}
|
||||
|
||||
export function middleware(req: NextRequest) {
|
||||
const path = req.nextUrl.pathname;
|
||||
|
||||
export function middleware(req: NextRequest) {
|
||||
const path = req.nextUrl.pathname;
|
||||
const hostname = req.headers.get('host')?.split(':')[0] || req.nextUrl.hostname;
|
||||
|
||||
if (hostname === 'qrmaster.net') {
|
||||
const url = req.nextUrl.clone();
|
||||
url.protocol = 'https';
|
||||
url.port = '';
|
||||
url.hostname = 'www.qrmaster.net';
|
||||
return NextResponse.redirect(url, 301);
|
||||
}
|
||||
|
||||
// 301 Redirects for /guide -> /learn to avoid duplicate content and consolidate authority
|
||||
if (path === '/guide/tracking-analytics') {
|
||||
return attachAttributionCookie(req, NextResponse.redirect(new URL('/learn/tracking', req.url), 301));
|
||||
@@ -57,9 +66,12 @@ export function middleware(req: NextRequest) {
|
||||
if (path === '/create-qr') {
|
||||
return attachAttributionCookie(req, NextResponse.redirect(new URL('/dynamic-qr-code-generator', req.url), 301));
|
||||
}
|
||||
|
||||
// Public routes that don't require authentication
|
||||
const publicPaths = [
|
||||
if (path === '/bar-code-generator' || path === '/barcode-generator') {
|
||||
return attachAttributionCookie(req, NextResponse.redirect(new URL('/tools/barcode-generator', req.url), 301));
|
||||
}
|
||||
|
||||
// Public routes that don't require authentication
|
||||
const publicPaths = [
|
||||
'/',
|
||||
'/pricing',
|
||||
'/faq',
|
||||
@@ -78,10 +90,9 @@ export function middleware(req: NextRequest) {
|
||||
'/bulk-qr-code-generator',
|
||||
'/qr-code-tracking',
|
||||
'/qr-code-analytics',
|
||||
'/reprint-calculator',
|
||||
'/barcode-generator',
|
||||
'/custom-qr-code-generator',
|
||||
'/manage-qr-codes',
|
||||
'/reprint-calculator',
|
||||
'/custom-qr-code-generator',
|
||||
'/manage-qr-codes',
|
||||
'/coupon',
|
||||
'/feedback',
|
||||
'/vcard',
|
||||
@@ -124,13 +135,29 @@ export function middleware(req: NextRequest) {
|
||||
return attachAttributionCookie(req, NextResponse.next());
|
||||
}
|
||||
|
||||
// Allow public paths
|
||||
// Allow public paths
|
||||
if (isPublicPath) {
|
||||
return attachAttributionCookie(req, NextResponse.next());
|
||||
}
|
||||
|
||||
// For protected routes, check for userId cookie
|
||||
const userId = req.cookies.get('userId')?.value;
|
||||
|
||||
const protectedPaths = [
|
||||
'/analytics',
|
||||
'/bulk-creation',
|
||||
'/create',
|
||||
'/dashboard',
|
||||
'/integrations',
|
||||
'/onboarding',
|
||||
'/qr',
|
||||
'/settings',
|
||||
];
|
||||
const isProtectedPath = protectedPaths.some(p => path === p || path.startsWith(p + '/'));
|
||||
|
||||
if (!isProtectedPath) {
|
||||
return attachAttributionCookie(req, NextResponse.next());
|
||||
}
|
||||
|
||||
// For protected routes, check for userId cookie
|
||||
const userId = req.cookies.get('userId')?.value;
|
||||
|
||||
if (!userId) {
|
||||
// Not authenticated - redirect to signup
|
||||
|
||||
Reference in New Issue
Block a user