โ† Back to Blog

Best Practices for UUIDs in URLs

2026-04-16 ยท 5 min read

UUID Format Conventions in URLs

When using UUID in URLs, follow these format conventions: always use lowercase (RFC 4122 recommended, and maintains consistency when URLs are case-sensitive); keep hyphens (standard UUID format, improving readability and recognizability); don't add curly braces ({} are illegal URL characters requiring encoding as %7B%7D, increasing URL length and complexity); UUIDs should appear only in path parameters, not as query parameters (unless business truly requires it). For example: /api/users/550e8400-e29b-41d4-a716-446655440000 is the correct format.

SEO Impact of UUID in URLs

For SEO-oriented content pages, using UUID directly in URLs is not ideal. Pure UUID URLs (like /articles/550e8400-e29b-41d4-a716-446655440000) contain no semantic information; search engines cannot infer page content from the URL, and they are difficult for users to remember and share. Better approaches: for SEO-facing public pages, use a slug (short descriptive string) as the URL component, using UUID only for APIs and internal systems; or adopt a slug + UUID hybrid format (like /articles/how-to-generate-uuid-550e8400), providing both SEO-friendliness and uniqueness guarantee; for pure APIs (no SEO requirements), UUID URLs are perfectly appropriate.

Routing Design Patterns

# ๅ…ธๅž‹่ทฏ็”ฑๆจกๅผ็คบไพ‹

# ๆจกๅผ1๏ผš็บฏ UUID๏ผˆAPI ่ทฏ็”ฑ๏ผŒๆŽจ่็”จไบŽๅ†…้ƒจ/ๅŽ็ซฏ๏ผ‰
/api/v1/users/550e8400-e29b-41d4-a716-446655440000
/api/v1/orders/9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d

# ๆจกๅผ2๏ผšslug + UUID ๆททๅˆ๏ผˆๅ…ฌๅผ€ URL๏ผŒSEO + ๅ”ฏไธ€ๆ€ง๏ผ‰
/blog/how-to-generate-uuid-550e8400e29b
# ไป…ๅ– UUID ๅ‰ 12 ๅญ—็ฌฆ็”จไบŽๅŽป้‡ๆ ‡่ฏ†

# ๆจกๅผ3๏ผšslug ๅช๏ผˆ็บฏ SEO๏ผŒ้œ€่ฆๆ•ฐๆฎๅบ“็กฎไฟ slug ๅ”ฏไธ€๏ผ‰
/blog/how-to-generate-uuid

# ๆจกๅผ4๏ผš็Ÿญ็ ๏ผˆ็”จๆˆทๅ‹ๅฅฝ๏ผŒ้€‚ๅˆ้‚€่ฏท้“พๆŽฅ็ญ‰๏ผ‰
/invite/abc123def
# ไฝฟ็”จ NanoID ็”Ÿๆˆ 8-12 ๅญ—็ฌฆ็Ÿญ็ 

# Django URL ่ทฏ็”ฑ้…็ฝฎ
from django.urls import path, re_path
import uuid

urlpatterns = [
    # ็ฑปๅž‹ๅฎ‰ๅ…จ๏ผšDjango ่‡ชๅŠจ้ชŒ่ฏ UUID ๆ ผๅผ
    path('api/users/<uuid:user_id>/', views.user_detail),

    # ๆญฃๅˆ™ๆ–นๅผ๏ผˆๆ›ด็ตๆดป๏ผ‰
    re_path(r'^api/items/(?P<item_id>[0-9a-f-]{36})/$', views.item_detail),
]

Case Sensitivity Issues

The HTTP specification states that URL paths are case-sensitive, meaning /users/550E8400-... and /users/550e8400-... are technically different URLs. To avoid confusion from case issues: on the server side, normalize all UUID path parameters to lowercase before processing; return 301 redirects for uppercase UUID URLs to their lowercase versions (maintaining canonicality); in client code, always generate and pass UUIDs in lowercase; in databases, UUID comparisons should use case-insensitive methods (or store consistently as lowercase). This avoids the awkward situation of "record exists in database but uppercase URL returns 404."

UUID Security Considerations in URLs

Exposing UUID in URLs has several security considerations: UUIDs appear in HTTP Referer headers and may be exposed to third-party resources (when images and scripts are loaded, they carry the current page URL); UUIDs appear in browser history, log systems, and CDN logs; for sensitive resources (like private file download links), UUIDs serve as "capability URLs" providing some protection, but should have an access control layer (don't grant access based on UUID knowledge alone); you can add time limits to sensitive UUID URLs (with signatures or expiry times), like GitHub's blob download links.

Using UUID Without Hyphens in URLs

Some developers use compact UUID without hyphens (32 characters) in URLs to shorten URL length. This is acceptable, but note: no-hyphen format is less intuitive in URLs (difficult to immediately recognize as UUID); if mixing hyphenated and non-hyphenated formats, normalization is needed at the routing level; it's recommended to clearly specify in API documentation which format is used to avoid caller confusion. Another option is encoding UUID's 128 bits with Base64 or Base58, getting a shorter (22-character Base64 or 22-character Base58) but equally informative ID.

Try the free tool now

Use Free Tool โ†’