OnlineFreeTools.org
  • Home
  • Tools
    Health & body →
    BMI Calculator — How to Calculate Body Mass IndexBMR & TDEE Calculator — How to Calculate Daily CaloriesBody Fat Calculator — How to Estimate Body Fat PercentageHeart Rate Zone CalculatorIdeal Weight Calculator — How to Estimate Ideal Body WeightMacro Calculator — Calories to Protein Carb Fat GramsOne-Rep Max Calculator (Epley)Pace Calculator — min/km and Speed
    Personal money →
    CAGR Calculator — How to Calculate Compound Annual Growth RateCompound Interest Calculator — How to Calculate Future ValueDebt Payoff Calculator — Months to Clear a BalanceDiscount Calculator — How to Calculate Sale PriceEMI Calculator — How to Calculate Loan PaymentsInflation Calculator — Future Purchasing PowerPercentage Change Calculator — From Old Value to NewPresent Value Calculator — PV and FV ModesRule of 72 Calculator — Years to DoubleSalary to Hourly Calculator — How to Convert Pay RatesTip Calculator — Tip Amount and SplitVAT / GST Calculator — Add or Extract Tax
    Business finance →
    Break-Even Calculator — How to Calculate Break-Even PointContribution Margin Calculator — Price Minus Variable CostGross Margin Calculator — How to Calculate Gross MarginIRR Calculator — Internal Rate of ReturnHow to Calculate Marginal Revenue — MR Calculator (ΔTR / ΔQ)Markup Calculator — How to Calculate Markup PercentageHow to Calculate NPV — Net Present Value CalculatorPayback Period Calculator — Years to Recover InvestmentProfit Margin Calculator — Net or Operating MarginROI Calculator — How to Calculate Return on Investment
    Math & stats →
    Confidence Interval Calculator — How to Calculate a CIExponent Calculator — How to Calculate PowersGPA Calculator — How to Calculate Weighted GPALogarithm Calculator — How to Calculate LogsMean Calculator — Average of a Number ListMedian and Mode CalculatorP-Value Calculator — How to Calculate a P-ValuePermutation and Combination CalculatorQuadratic Equation Solver — Roots and DiscriminantSample Size Calculator — How to Estimate Required nScientific Notation Calculator — How to Convert Scientific NotationSignificant Figures Calculator — How to Count and Round Sig FigsStandard Deviation Calculator — How to Calculate SD and VarianceZ-Score Calculator — How to Calculate a Standard Score
    Geometry & measure →
    Aspect Ratio Calculator — How to Calculate and Scale RatiosCircle Calculator — Area and CircumferenceGradient Calculator — Multivariable ∇f (Partial Derivatives)Pythagorean Theorem Calculator — How to Find a Missing SideSlope Calculator — How to Calculate Slope Between Two PointsTriangle Area CalculatorVolume Calculator — Box and SphereUnit Converter — Length / Mass / Temperature / Area / Volume / Speed
    Science & physics →
    Acceleration Calculator — Change in VelocityDensity Calculator — Mass over VolumeOhm’s Law Calculator — Resistance and PowerVelocity Calculator — Distance over TimeMeasuring Magnetic Fields — Field strength calculator
    Home & DIY →
    Concrete Calculator — How to Estimate Concrete VolumePaint Calculator — How to Estimate Paint NeededTile Calculator — How to Estimate Tile QuantitySquare Feet to Square Meters — Area Converter for Homes & Renovation
    Time & calendar →
    Age Calculator — Chronological Age from BirthdateDate Difference Calculator — Days and WeeksTime Zone Converter — Compare One Moment WorldwideUnix Timestamp Converter — Epoch ↔ Readable Time
    PDF & docs →
    Batch compress PDFs for emailCompress PDF — Shrink File Size in Your BrowserCrop PDF — Trim Page Margins in Your BrowserMerge PDF — Combine Files in Your BrowserOrganize PDF — Reorder or Remove Pages in Your BrowserAdd Page Numbers to PDF — In Your BrowserPDF Page to Image Sizes — Multi-Size Export PackPDF to JPG — Convert Pages to Images in Your BrowserPDF to Markdown — Extract Text for Notes in Your BrowserPDF Watermark — Stamp Text on Every Page in Your BrowserProtect PDF — Password-Encrypt in Your BrowserRotate PDF — Fix Page Orientation in Your BrowserSplit PDF — Extract Pages LocallyUnlock PDF — Remove Password You Already Know
    Image & media →
    Add Text Watermark to Photo — Local Browser ToolAmazon main image sizeApple-touch-icon 180×180Batch watermark product photosBulk compress PNG imagesBulk compress product photos (JPEG, PNG, WebP)Bulk convert images to JPGBulk convert images to PNGBulk convert images to WebPExtract Colors from Image — Palette & Click PickFlip Image — Mirror Horizontally or VerticallyAdd Border to Image — Color & Width OnlineImage Compressor — Resize, Quality & Target Size LocalCrop & Resize Image — Local Aspect PresetsPhoto EXIF Viewer & Remover — GPS, Camera & Local StripImage Format Converter — PNG JPEG WebP AVIF BMP GIF ICO SVGConvert Image to Grayscale — Black & White OnlineMerge Images — Combine Photos into One CollageImage Optimizer — WebP, AVIF & MozJPEG LocalOverlay Images — Put a Logo on a PhotoImage to Base64 Converter — Encode & Decode LocallyImages to GIF — Make an Animated GIF LocallyImages to PDF — Combine Photos into One FileImages to PowerPoint — Photos to PPTX SlidesImages to Word — Build a DOCX from PhotosInstagram post sizeInstagram story sizeiOS app icon sizeiPhone 6.9 screenshot sizeLinkedIn banner sizeOpen Graph image sizeSVG optimizerYouTube thumbnail size
    Design & brand →
    Generate Brand Color Scale — 50–950 Palette & CSS TokensBrand Style Guide — Generate a Modular Draft You Can EditSmart Website Color Scheme — Semantic CSS TokensWCAG Contrast Checker — AA/AAA Ratio Online
    SEO & growth →
    Check if a URL is blocked by robots.txtCheck SSL certificate expirationCore Web Vitals CheckerFind and validate XML sitemapHreflang GeneratorIndexNow — Bing URL Submit, Key Check & Status CodesGoogle SERP PreviewMeta Tag GeneratorOn-Page SEO CheckerOpen Graph PreviewRobots.txt GeneratorJSON-LD Schema GeneratorXML Sitemap GeneratorSPF DKIM DMARC checkerUTM BuilderValidate security.txt
    Network & IP →
    Add WWW to DNS — A/CNAME, Apex Rules & Provider GuidesAWS VPC CIDR planner — Split a VPC into AZ subnetsCIDR cheat sheet — Click a prefix to see mask and hostsCIDR to IP range — Expand a prefix into usable addressesDomain Lookup — Check DNS Records & Registration OnlineWhat Is My IP Address — See Your Public IP (IPv4 or IPv6)IP range to CIDR — Turn start–end addresses into prefix listsIPv6 CIDR calculator — Expand a prefix into its address rangePrivate CIDR ranges — Check if an IP or prefix is private or special-useTerraform cidrsubnet — Get the child CIDR Terraform would returnCheck HTTP Response Headers
    Dev & data →
    Base64 Encode & Decode — Convert Text in Your BrowserChatGPT export to MarkdownCSV ↔ JSON Converter — Types, Delimiters & Localcurl to fetchHTML Entity Encoder & Decoder — Escape, Unescape & LocalJSON Schema Validator — Draft-07 Paths & LocalJWT Decoder — Read Header & Payload Locally (No Verify)Markdown ↔ HTMLYAML ↔ JSON Converter — Types, Multi-doc & Local
    AI prompt tools →
    Android prompt builder — Local + Optional AIFilm prompt builder — Local + Optional AIiOS prompt builder — Local + Optional AIMidjourney prompt builder — Local + Optional AIProduct design prompt builder — Local + Optional AIPrompt template builder — Local + Optional AIShort drama prompt generator — Local + Optional AISketch.app prompt generator — Local + Optional AIWriting prompt generator — Local + Optional AI
    Text compare →
    Compare two text files onlineCompare two Word documents for differencesExcel compare filesJSON diff checker onlineCheck difference between two texts
    Security & IDs →
    Batch checksum release filesFile Hash Checker — Verify Digests in Your BrowserFile metadata analyzerRandom Password Generator — Create Passwords LocallyUUID & ULID Generator — Create IDs in Your Browser
    Files & archives →
    Archive Extractor Online — Open Compressed Files in Your BrowserCreate zip fileMagnet Link Decoder — Parse Info Hash and Trackers LocallyUnzip File Online — Extract ZIP Files in Your Browser
  • Tool topics
  • Tool types
  • Dev Logs
☕ Buy me a coffee

Navigation

Home

Visiting /en/ then clicking a Tools mega link lands on /zh/tools/... because English tool hrefs are unprefixed and Accept-Language re-negotiates. | Dev Logs

Back to Logs

Date: 2026-09-03 19:29 Summary: Visiting /en/ then clicking a Tools mega link lands on /zh/tools/... because English tool hrefs are unprefixed and Accept-Language re-negotiates. Visibility: people

[question] 为什么选择了 http://localhost:8788/en/ 后,点击页面的tools,会跳转到http://localhost:8788/zh/tools/bulk-compress-product-photos

[try to solve]

Context

A user opened the explicit English home (/en/), then used the nav Tools mega menu and ended on a Chinese tool URL (/zh/tools/bulk-compress-product-photos) instead of staying in English.

Process

  1. Inspected public/en/index.html: Tools mega links for tools use unprefixed paths such as href="/tools/bulk-compress-product-photos" (English is the default SEO language; canonical tool URLs omit /en/).
  2. Read Worker middleware in src/index.ts (app.use("/*", ...)): for HTML GET requests without an explicit lang segment, it runs pickLang(Accept-Language) and, if the pick is not the default (en), issues a 302 to withLangPrefix(picked, pathname).
  3. Confirmed with curl (GET, not HEAD — HEAD skips the redirect because the middleware only runs for GET):
    • GET /tools/bulk-compress-product-photos + Accept-Language: zh-CN → 302 Location: /zh/tools/bulk-compress-product-photos
    • GET /en/ stays on English (explicit prefix bypasses negotiation)
    • GET /en/tools/... also stays English (explicit prefix)

Root cause / analysis

Two intentional design pieces collide for Chinese-browser users who manually chose English:

  1. Default-lang URLs are unprefixed (withLangPrefix returns /tools/... for en). So the /en/ home still emits English-canonical hrefs without /en/.
  2. Accept-Language negotiation only looks at the request path + browser header, not “user already chose /en/”. Leaving /en/ for an unprefixed tool link drops the explicit choice and re-applies zh from the browser.

/topics, /about, etc. are excluded from this middleware; /tools/... is not, so tool clicks are affected.

Note: curl -I (HEAD) will not reproduce the 302; use GET.

Solution

No code change in this Q&A — behavior is explained as designed today.

If we want “stay on English after visiting /en/”, options (product decision):

  • Remember explicit lang in a cookie / localStorage and skip or override Accept-Language when set
  • On /en/ pages, emit /en/tools/... hrefs for in-site navigation (SEO can keep unprefixed as canonical)
  • Prefer Referer /en/... when deciding whether to negotiate

Workaround for local QA: open /en/tools/bulk-compress-product-photos directly, or temporarily use an English Accept-Language.

Notes / boundaries

  • Relevant code: src/index.ts (middleware ~380–441), src/site/lang.ts (pickLang, withLangPrefix)
  • Home route / also negotiates; only explicit /{lang}/ home skips it
  • This is UX friction for bilingual testers, not a wrong href pointing at /zh/... in the English HTML

[actions]

  • Diagnosed via HTML inspection + GET curl against localhost:8788; no product code changed
OnlineFreeTools.org · Learning project · Iterating
About·Privacy·Terms·Contact·GitHub