惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
博客园 - 聂微东
博客园 - Franky
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
雷峰网
雷峰网
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
L
LangChain Blog
WordPress大学
WordPress大学
H
Help Net Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Y
Y Combinator Blog
Blog — PlanetScale
Blog — PlanetScale
MyScale Blog
MyScale Blog
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
罗磊的独立博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
有赞技术团队
有赞技术团队
Apple Machine Learning Research
Apple Machine Learning Research
云风的 BLOG
云风的 BLOG
博客园 - 【当耐特】
P
Proofpoint News Feed
D
DataBreaches.Net

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
URL Encoding Explained: Why %20 Appears in URLs (and How ...
Snappy Tools · 2026-04-26 · via DEV Community

Snappy Tools

You paste a URL into your browser and it looks like this:

https://example.com/search?q=hello%20world&filter=price%3E100

Enter fullscreen mode Exit fullscreen mode

What are all those %20 and %3E symbols? Why does a space become %20? And why does > become %3E?

This is URL encoding (also called percent-encoding), and understanding it will save you from a category of bugs that trips up developers at every experience level.

Why URLs cannot contain raw special characters

A URL is a string of ASCII text with strict rules about which characters are allowed. Characters like spaces, #, ?, &, =, and > all have specific meanings in URL structure. If you include them literally in a query parameter, the browser or server will misinterpret the URL.

For example, this URL is ambiguous:

https://example.com/search?q=cats & dogs

Enter fullscreen mode Exit fullscreen mode

Does the space end the URL? Is & another parameter separator? The parser cannot tell.

URL encoding solves this by replacing unsafe characters with a % sign followed by the character's two-digit hexadecimal ASCII code.

The encoding table (most common characters)

Raw character Encoded Notes
Space %20 Also sometimes encoded as + in form data
+ %2B Literal plus sign in query strings
= %3D Equals sign inside a value
& %26 Ampersand inside a value
# %23 Hash inside a path or query
/ %2F Forward slash inside a value
: %3A Colon inside a value
? %3F Question mark inside a value
@ %40 At sign
< %3C Less-than
> %3E Greater-than
" %22 Double quote
{ %7B Left curly brace
} %7D Right curly brace

Two modes you need to know

Full URL encoding

Encodes everything except letters, digits, and -_.~. Use this when encoding an entire URL for transport (e.g. embedding one URL inside another as a query parameter).

encodeURIComponent("https://example.com/path?q=hello world")
// → "https%3A%2F%2Fexample.com%2Fpath%3Fq%3Dhello%20world"

Enter fullscreen mode Exit fullscreen mode

Query string value encoding

Only encodes the characters that would break a query string. Use this for encoding individual parameter values. In JavaScript, encodeURIComponent() is the right function — not encodeURI(), which leaves structural characters like ? and & untouched.

// WRONG — encodeURI leaves = and & unencoded
encodeURI("price=100&color=red&blue")

// RIGHT — encodeURIComponent encodes everything unsafe
encodeURIComponent("price=100&color=red&blue")
// → "price%3D100%26color%3Dred%26blue"

Enter fullscreen mode Exit fullscreen mode

Common mistakes

1. Double-encoding

If you encode an already-encoded URL, %20 becomes %2520 (because % itself gets encoded to %25). Always decode first, then re-encode if needed.

2. Using encodeURI instead of encodeURIComponent

encodeURI is designed for full URLs. It will not encode :, /, ?, #, &, or =. For individual query parameter values, always use encodeURIComponent.

3. Forgetting that + means space in form data

When a form is submitted with method="GET", browsers encode spaces as + rather than %20. PHP's urldecode() handles both; JavaScript's decodeURIComponent does not handle + as a space. You need to replace + with %20 first if you are decoding form data in JavaScript.

function decodeFormValue(str) {
  return decodeURIComponent(str.replace(/\+/g, '%20'));
}

Enter fullscreen mode Exit fullscreen mode

How to decode a messy URL quickly

Instead of manually translating each %XX code, use a URL decoder tool. Paste the encoded URL, get the readable version instantly.

👉 URL Encoder / Decoder — SnappyTools

It handles both full URL encoding and query string encoding modes, shows the decoded output in real time, and works entirely in your browser — nothing is sent to a server.

TL;DR

  • URLs can only contain safe ASCII characters; special characters must be percent-encoded
  • %20 = space, %26 = &, %3D = =, %2F = /
  • Use encodeURIComponent() (not encodeURI()) for query string values in JavaScript
  • Watch out for double-encoding and the + = space convention in form data

Have a URL that is not decoding correctly? Drop the encoded string in the comments and I will help you debug it.