レッスン 3

Relative URLs and Normalization 日本語ガイド

日本語の url parser relative urls and normalization ガイド: Resolve relative paths, preserve intent, and avoid accidental canonical changes.

このコンテンツはまだ日本語で用意されていません。ローカライズが完了するまで English 版を表示しています。

Not every URL you see is absolute. HTML, routers, redirects, and config files often use relative URLs.

/account/settings
../images/logo.png
?page=2

Relative URLs need a base URL before they can be resolved.

Base matters

Given this base:

https://example.com/docs/guides/url/

../api/ resolves to:

https://example.com/docs/guides/api/

If the base changes to /docs/guides/url, without a trailing slash, resolution can change because the last segment may be treated as a file.

Normalization

Normalization makes equivalent-looking URLs consistent. Examples include:

  • Removing default ports
  • Resolving . and .. path segments
  • Lowercasing host names
  • Sorting query parameters for a canonical form

Normalization is useful, but it can be dangerous when byte-for-byte identity matters.

Preserve intent

Avoid normalizing signed URLs, cache keys, OAuth redirects, or third-party callback links unless you know the exact canonicalization rules. A harmless-looking rewrite can invalidate a signature or change which endpoint receives a request.

Parsing helps because it lets you see what will change before you rebuild the URL.

実践したいときは関連する DevCove ツールを使えます。任意であり、このレッスンの必須部分ではありません。

関連ツールを開く

コース概要へ戻る