URLエンコード・URLデコード変換ツール

日本語、空白、記号、クエリパラメータをURLで使える%xx形式にエンコードし、URLデコードで元の文字列へ戻せます。encodeURIComponentの確認にも使える無料ツールです。

よくある質問

URLエンコードとは?日本語や空白をURLで使える形にする仕組み

URLエンコードは、日本語、空白、記号などをURLで安全に送れる文字列へ変換する方法です。文字はUTF-8のバイト列に変換され、%E3%81%82 のようなパーセントエンコード形式になります。検索語、クエリパラメータ、リダイレクトURLをURLに入れるときに使います。

URLデコードとURLエンコードはどのように変換されますか?

URLエンコードでは、空白は %20、& は %26、? は %3F のように変換されます。URLデコードでは、これらの%xx表記を元の文字へ戻します。JavaScriptでクエリ値を作る場合は、URL全体ではなく値だけに encodeURIComponent() を使うのが一般的です。

URLエンコード変換表(空白・&・?・=・+)

URLデコードやURLエンコードでよく確認される文字と、対応するパーセントエンコード表記です:

予約文字

文字URL エンコード説明
#%23シャープ記号(URL フラグメントに使用)
$%24ドル記号
&%26アンパサンド(URL パラメータの区切りに使用)
+%2Bプラス記号
,%2Cカンマ
/%2Fスラッシュ(URL パスセパレータ)
:%3Aコロン
;%3Bセミコロン
=%3D等号(URL パラメータ割り当て)
?%3F疑問符(URL クエリ文字列の開始)
@%40アットマーク
[%5B開き角括弧
]%5D閉じ角括弧

その他の一般的な文字

文字URL エンコード説明
Space%20URL エンコードが必要な最も一般的な文字
!%21感嘆符
"%22二重引用符
%%25パーセント記号(URL エンコードのエスケープ文字)
'%27一重引用符
(%28開き括弧
)%29閉じ括弧
*%2Aアスタリスク
\%5Cバックスラッシュ
^%5Eキャレット
{%7B開き波括弧
|%7C縦棒
}%7D閉じ波括弧
~%7Eチルダ

JavaScript・Python・PHPでのURLエンコード実装例

URLエンコードとURLデコードをコードで実装する場合の例です。APIのクエリパラメータ、検索キーワード、コールバックURLのデバッグに使えます:

Frontend / Scripting

JavaScript

// URL encoding
const text = "Hello World! Special chars: &?=/";
const encoded = encodeURIComponent(text);
console.log("Encoded:", encoded);

// URL decoding
const decoded = decodeURIComponent(encoded);
console.log("Decoded:", decoded);

TypeScript

// URL encoding
const text: string = "Hello World! Special chars: &?=/";
const encoded: string = encodeURIComponent(text);
console.log("Encoded:", encoded);

// URL decoding
const decoded: string = decodeURIComponent(encoded);
console.log("Decoded:", decoded);

Python

import urllib.parse

# URL encoding
text = "Hello World! Special chars: &?=/"
encoded = urllib.parse.quote(text)
print(f"Encoded: {encoded}")

# URL decoding
decoded = urllib.parse.unquote(encoded)
print(f"Decoded: {decoded}")

Backend / Systems

Go

package main

import (
    "fmt"
    "net/url"
)

func main() {
    // Encode a URL
    text := "Hello World! Special chars: &?=/";
    encoded := url.QueryEscape(text)
    fmt.Println("Encoded:", encoded)

    // Decode a URL
    decoded, err := url.QueryUnescape(encoded)
    if err == nil {
        fmt.Println("Decoded:", decoded)
    }
}

PHP

<?php
// URL encoding
$text = "Hello World! Special chars: &?=/";
$encoded = urlencode($text);
echo "Encoded: " . $encoded . "\n";

// URL decoding
$decoded = urldecode($encoded);
echo "Decoded: " . $decoded . "\n";
?>

C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

// Function to URL-encode a string
char *url_encode(char *str) {
    char *encoded = malloc(strlen(str) * 3 + 1);
    char *pstr = str;
    char *pbuf = encoded;

    while (*pstr) {
        if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~') {
            *pbuf++ = *pstr;
        } else if (*pstr == ' ') {
            *pbuf++ = '+';
        } else {
            sprintf(pbuf, "%%%.2X", *pstr);
            pbuf += 3;
        }
        pstr++;
    }
    *pbuf = '\0';

    return encoded;
}

int main() {
    char *text = "Hello World! Special chars: &?=/";
    char *encoded = url_encode(text);

    printf("Original: %s\n", text);
    printf("Encoded: %s\n", encoded);

    free(encoded);
    return 0;
}

encodeURI と encodeURIComponent の違い

encodeURI() は完成済みのURL全体を扱うため、/、?、&、=、# などURL構造に必要な文字を残します。 encodeURIComponent() はクエリパラメータの値など、URLの一部分を安全に入れるための関数で、& や = もエンコードします。 検索キーワードやリダイレクトURLをパラメータ値として渡す場合は、通常 encodeURIComponent() の結果を確認するのが安全です。

URL エンコードのデバッグチェックリスト

二重エンコード

%2520 が見える場合、%20 のパーセント記号がさらに %25 としてエンコードされています。再度エンコードする前に一度デコードして実際の値を確認してください。

空白は + か %20 か

HTML フォームエンコードでは空白が + になることがあり、URL コンポーネントのエンコードでは通常 %20 を使います。署名やキャッシュキーを比較する前に API が期待する形式を確認してください。

パスとクエリ値

スラッシュはパスでは構造を表しますが、クエリ値の中では通常エンコードすべきです。完成済みの URL 全体ではなく、個別のパラメータ値をエンコードしてください。

Unicode パラメータ

日本語、emoji、その他の非 ASCII 文字はまず UTF-8 バイトになり、その後パーセントエンコードされます。文字化けする場合は元テキストが別の文字エンコーディングである可能性があります。

URLエンコード・URLデコードの実用例

安全な手順は、URL全体ではなくクエリパラメータの値だけをエンコードすることです。以下は検索キーワード、リダイレクトURL、+記号、日本語文字列の変換例です。

空白を含む検索語

元の値
q=hello world
エンコード後
q=hello%20world

クエリ値の空白はエンコードします。フォーム送信では + になることもありますが、一般的なURLコンポーネントでは %20 が扱いやすいです。

コールバックURLをパラメータにする

元の値
redirect=https://example.com/a?x=1&y=2
エンコード後
redirect=https%3A%2F%2Fexample.com%2Fa%3Fx%3D1%26y%3D2

入れ子のURLに含まれる ? や & をエンコードしないと、外側のクエリ文字列が壊れます。

意味のあるプラス記号

元の値
phone=+1 555 0100
エンコード後
phone=%2B1%20555%200100

未エンコードの + はフォームデコーダーで空白として扱われる場合があります。意味のあるプラス記号は %2B にします。

Unicodeキーワード

元の値
tag=中文✅
エンコード後
tag=%E4%B8%AD%E6%96%87%E2%9C%85

非ASCII文字はUTF-8バイトに変換され、その後パーセントエンコードされます。