Production 301 Canonical Rules for Nginx, Apache .htaccess, PHP & Next.js

Writing rewrite rules from scratch often triggers infinite redirect loops behind CDNs or reverse proxies.

Scan Your Site Free ->

Production 301 Canonical Rules for Nginx, Apache .htaccess, PHP & Next.js

Telemetry Evidence & Root Cause

Broken redirect chains are one of the top P1 causes of sudden deindexation and GSC click drops during site migrations.

How Screening Dog Solves It

Screening Dog generates stack-specific, loop-safe snippets tailored to your exact domain's www and trailing-slash convention.

Live Benchmark Dataset

Aggregated from anonymized production crawls & technical audit telemetry.

MetricObserved SampleTop Quartile TargetSEO / Business Impact
Average hop reduction after deployment2.3 hops -> 1 hop1.0 hopEliminates redirect chain warnings
Time to verify fix live< 3 secondsMachine QA verificationZero guesswork after deploy

Comparison Matrix

DimensionLegacy Tool / ManualScreening Dog Cloud OS
Stack CoverageGeneric Apache blog snippetsTailored Nginx, Apache .htaccess, PHP Guard & Next.js Middleware
Domain AccuracyPlaceholders like example.comPre-filled with crawled host & trailing-slash signature
VerificationManual incognito testInstant re-check via Screening Dog Kanban & Monitor

Server / Code Config to Apply: Nginx Single-Hop Canonical Enforcement

Where to apply: /etc/nginx/conf.d/canonical.conf (Site Nginx Server Block)

merge_slashes on;
server {
    listen 80;
    server_name example.com www.example.com;
    return 301 https://example.com$request_uri;
}
if ($request_uri ~* "^(.*)/index\.(php|html?)
quot;) { return 301 https://example.com$1/; }

Frequently Asked Questions

Should Next.js apps use middleware.ts for uppercase URLs?

Yes. Next.js handles trailingSlash in next.config.ts, while middleware.ts cleanly redirects mixed-case paths and non-canonical hosts via HTTP 308.