seo.url_encode.how_desc
- seo.url_encode.how_step1
- seo.url_encode.how_step2
- seo.url_encode.how_step3
- seo.url_encode.how_step4
seo.url_encode.how_example
Encode text for safe use in URLs. Converts special characters to percent-encoded format.
URL encoding, also known as percent encoding, is a mechanism for encoding special characters in URLs. URLs can only contain certain characters from the ASCII set, so other characters must be converted to a valid format.
seo.url_encode.how_desc
seo.url_encode.how_example
URL encoding was standardized in RFC 3986 (2005), which defines the Uniform Resource Identifier (URI) syntax. The standard specifies which characters are "unreserved" (safe to use as-is: A-Z, a-z, 0-9, -, _, ., ~) and which are "reserved" (have special meaning: :, /, ?, #, [, ], @, !, $, &, ', (, ), *, +, ,, ;, =). Reserved characters must be percent-encoded when used literally in URLs. Before this standard, different systems used different encoding methods, leading to compatibility issues. RFC 3986 unified URL encoding across the web.
URL encoding makes data URL-safe but does not encrypt or secure it. Encoded URLs can be easily decoded. Always use HTTPS for sensitive data. Learn about encoding security
Every programming language provides URL encoding functions. Here are comprehensive examples:
// urlencode() - for form data (spaces become +)
$encoded = urlencode($data);
// rawurlencode() - RFC 3986 compliant (spaces become %20)
$encoded = rawurlencode($data);
// Building query strings
$params = http_build_query([
'search' => 'coffee & tea',
'category' => 'food/drink'
]);
// Result: search=coffee+%26+tea&category=food%2Fdrink
// encodeURIComponent() - for query parameters (use this!)
const encoded = encodeURIComponent('hello world & stuff');
// Result: hello%20world%20%26%20stuff
// encodeURI() - for complete URLs (rarely needed)
const fullUrl = encodeURI('https://example.com/path with spaces');
// Building URLs with parameters
const baseUrl = 'https://api.example.com/search';
const query = encodeURIComponent('[email protected]');
const url = `${baseUrl}?q=${query}`;
from urllib.parse import quote, quote_plus, urlencode
# quote() - RFC 3986 encoding
encoded = quote('hello world & stuff')
# Result: hello%20world%20%26%20stuff
# quote_plus() - form encoding (spaces become +)
encoded = quote_plus('hello world')
# Result: hello+world
# urlencode() - build query strings
params = urlencode({'search': 'coffee & tea', 'page': 1})
# Result: search=coffee+%26+tea&page=1
import (
"net/url"
"fmt"
)
// QueryEscape() - encode query parameter
encoded := url.QueryEscape("hello world & stuff")
// Result: hello+world+%26+stuff
// PathEscape() - encode path segments
encoded := url.PathEscape("hello/world")
// Result: hello%2Fworld
// Building URLs with parameters
u, _ := url.Parse("https://api.example.com/search")
q := u.Query()
q.Set("search", "coffee & tea")
u.RawQuery = q.Encode()
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
// URL encoding (always specify UTF-8)
String encoded = URLEncoder.encode("hello world & stuff",
StandardCharsets.UTF_8);
// Result: hello+world+%26+stuff
// Building URLs
String baseUrl = "https://api.example.com/search?q=";
String query = URLEncoder.encode("[email protected]",
StandardCharsets.UTF_8);
String fullUrl = baseUrl + query;
require 'uri'
require 'cgi'
# URI.encode_www_form_component() - standard encoding
encoded = URI.encode_www_form_component('hello world & stuff')
# Result: hello+world+%26+stuff
# CGI.escape() - alternative
encoded = CGI.escape('hello world')
# Building query strings
params = URI.encode_www_form({search: 'coffee & tea', page: 1})
# Result: search=coffee+%26+tea&page=1
using System;
using System.Web;
using System.Net;
// HttpUtility.UrlEncode() - standard encoding
string encoded = HttpUtility.UrlEncode("hello world & stuff");
// Result: hello+world+%26+stuff
// Uri.EscapeDataString() - RFC 3986 (no System.Web dependency)
string encoded = Uri.EscapeDataString("hello world & stuff");
// Result: hello%20world%20%26%20stuff
Need to decode URL-encoded strings? Use our URL Decoder to convert percent-encoded text back to readable format.
Encoding binary data? Try our Base64 Encoder for converting binary data to text format.
Displaying text on web pages? Use our HTML Entity Encoder to safely encode HTML special characters.