<-
Apache > HTTP Server > Documentation > Version 2.4

~ (Content Negotiation)

݋b _ _ Ɯ”. ٿ ~@ ݋ O[.

Hġb HTTP/1.1 Ծ࿡ v ~(content negotiation)@ Ѵ. ~@ media type, , ڻ\J, ΃ȵ  v xn ڿ J F@ Ѵ. u r b v ]@ ڷ Q[b ən .

⺻ڷ HϵǾb mod_negotiation ~ @ Ѵ.

Support Apache!

O

top

~

ڿ@ \ ٸ F@ ] . 齁, ٸ 𽁳 ٸ media type Ȥ@ ΰ ٸ F @ ] . F@ ø[b Ѱ Ҏ^@ ȝ~ڿ U ֽO ø[ [b ͓ƴ. ׵\ ݋L ڵڷ ø[b ͙n ɸ[. ƾb v ] Ϻη ׵ x[b F r V얿 ɸ[. 齁, vb u, ׵\ ^ٔR r OʹٽO ˷R ] . vb ] c ׵ x t. uε F@ ]ѴٔR vb ٞ .

Accept-Language: fr

Ʒ xb F 𽁺 ٸ 쿡 Oȴ.

ٞ@ ] v u @ ] , u x[O, \ media type@ @ ] , ^ zh پb HTML, ٸ media type پb GIF JPEG@ xѴٽO ˷ش.

Accept-Language: fr; q=1.0, en; q=0.5
Accept: text/html; q=1.0, text/*; q=0.8, image/gif; q=0.6, image/jpeg; q=0.6, image/*; q=0.5, */*; q=0.1

Hġb HTTP/1.1 Ծ࿡ rǵ '݋L ֙n(server driven)' ~@ Ѵ. Hġb Accept, Accept-Language, Accept-Charset, Accept-Encoding ] c Ѵ. , Hġb RFC 2295 RFC 2296 rǵ ~ 'ڿz\(transparent)' ] cn Ѵ. ׵\ RFC rǵ ' (feature negotiation)'@ [ ʾb.

ڿ(resource)@ (RFC 2396) URI 亰[b Z. Hġ @ ݋Lb ڿ F(representations)@ Ѵ. F@ r media type, ڻ\J, ΃ȵ @ ٓh ǘ. ڿ@ \ F (Vξb ^@ ]n ) ȴ. ڿ \ F ٔR ڿ@ 󰡴ɸ[ٽO(negotiable) θ, V F@ (variant)ƶO Ѵ. 󰡴 ڿ v (dimension)O Ѵ.

top

ڿ@ [ ݋Lb r ʿ[. ٞ ΰ Ҏ^ [ r b:

type-map H ȝ~[

type map@ type-mapƶ ڵ\ (Ȥ@ Hġ r xȯ@ MIME type application/x-type-map) ݋. @ ȝ~[R r݋ type-map ڵ\ H Ȯڸ rؾ Ѵ. ݋L rHϿ ٞ r[b ͓ .

AddHandler type-map .var

Type map Hϻ@ ش[b ڿ Ɠ ƾ [O, H Ѵ. H@ \ HTTPe c R 伺ȴ. H@ R Ѵ. Hȿ݋ R@ ȝ~ ] ^. (Ʒ ʿ䰡 ^O, n C[) \ H ڷ O b ~ڷ map H@ C۸[b ͓ ƴ. ٞ@ map H . H Ɠ@ foo.var, foob ڿ@ Ѵ.

URI: foo

URI: foo.en.html
Content-type: text/html
Content-language: en

URI: foo.fr.de.html
Content-type: text/html;charset=iso-8859-2
Content-language: fr, de

typemap Hϓ Hϸ Ȯ , U Multiviews ȝ~[n, 켱@ @ Ǹ[. ݋ ٸ ǰ@ ٔR, ٞ (JPEG, GIF, ASCII-art ش[b) media type "qs" Hͷ ǰ(source quality)@ FC ] :

URI: foo

URI: foo.jpeg
Content-type: image/jpeg; qs=0.8

URI: foo.gif
Content-type: image/gif; qs=0.5

URI: foo.txt
Content-type: text/plain; qs=0.01

qs @@ 0.000݋ 1.000 ȝƴ. qs @ 0.000 @ õ ʞ@ Ǹ[. 'qs' @ ^b @ 1.0ڷ ޵ȴ. qs @@ Ŭƾh ɷ°b ^ ٸ 񱳸[ 'ǰ'@ t. 齁, ȝ@ tb JPEG Hϓ ASCII HϺپb H @ ǰ@ . ׵\ ڿ E ASCII artٔR ASCII F JPEG F @ ǰ@ ] . ׵\Ƿ qs @@ F[b ڿ ٸ.

[b c U@ mod_negotation typemap ݋ O[.

Multiviews

MultiViewsb 丮 ӛƹǷ, apache2.conf <Directory>, <Location>, <Files> ӛ Ȥ@ (AllowOverride rǾٔR) .htaccess H Options C r ] . Options All@ MultiViews `[ʞ@ Ǹ[. Y Ѵ.

MultiViews ȝ~[R ٞ @ ϓ Ͻ: ݋L /some/dir/foo ]@ ޽O /some/dir/foo MultiViews ۸[ /some/dir/foo Z[ @ , ݋Lb 丮݋ Ɠ foo.* Hϵ@ `[b type map@ 늴. Ŭƾh ] media type content-encoding@ O ߿ J @ Ѵ.

MultiViewsb ݋L 丮 V H@ ãb DirectoryIndex Cn ~ȴ. rHϓ ٞ ٔR,

DirectoryIndex index

index.html index.html3 ٔR ݋Lb Ƶ ߿ [ rѴ. ^O index.cgi ٔR, ݋Lb װ@ Ѵ.

丮 @V H [ Charset, Content-Type, Language, Encoding ǸZ[b mod_mime 𸣾b Ȯڸ ٔR, b MultiViewsMatch C r ޷Ǵ. Cb ڵ\, , ٸ Ȯ MultiViews θ rѴ.

top

Ҏ^

Hġ type-map HϓƳ 丮 b Hϸ ֽ ڿ U@ ԵǔR '' @ r[ Ҏ^ [ ȝ~Ѵ. Hġ ~ @ ȝ~[ rȮ Ͻb ڼ ʿb ^. ׵\ ñ ȝ@ Ҏ^@ Ѵ.

ΰ Ҏ^ :

  1. Hġ ˽O@ ȝ~[ ݋L ֙n[b @ ^ 쿡 ȝ~Ѵ. Hġ ˽O@ E݋ ڼ Ѵ. ˽O@ ȝ~[R Hġb @ vv Ưr ǰ](quality factor) 'Ѵ'. Hġ ǰ] ۸[b Ҏ^@ E݋ ڼ Ѵ.
  2. ڿz\(Transparent) ~@ v RFC 2295 rǵ Ҏ^ڷ ] 쿡 ȝ~Ѵ. Ҏ^@ '' @ r @ v οѴ. E݋ b v ˽O ޷ȴ. ڿz\ r߿ vb Hġ RFC 2296 rǵ ' ˽O(remote variant selection algorithm)'@ ] ] .

Media Type vb Accept c x t. H@ ǰ] ] . n ǰ] ("qs" H) ] .
Language vb Accept-Language c x t. H@ ǰ] ] . @ \ 𽁸 (Ȥ@ ƹ 𽁙n ^@) ] .
Encoding vb Accept-Encoding c x t. H@ ǰ] ] .
Charset vb Accept-Charset c x t. H@ ǰ] ] . @ media type Hͷ ڻ\J@ tm ] .

Hġ ˽O

Hġb v m '' @ (ٔR) ø[ E ˽O@ ȝ~Ѵ. ˽O@ ] ^. ٞ Ѵ:

  1. v, ش[b Accept* c ȝ[O, ǰ@@ ׃. Accept* c ޾Ƶ ʾb @ ݋ Ѵ. n ʙڔR 4 Z .
  2. ݋ [ ܸ[ '' @ ãb. ٞ ȝb b݋ Ͻ. ȝ݋ õʻ@ @ ܵȴ. ȝ ڔR Ƹ ڷ ø[O 3 Z . \ ڔR ٞ ȝ Ѵ.
    1. Accept c ǰ] media type ǰ@@ [ @ @@ @ Ѵ.
    2. @ (language) ǰ] @ Ѵ.
    3. Accept-Language c (ٔR) b݋ Ȥ@ LanguagePriority C (ٔR) b݋ O J 𽁸 @ Ѵ.
    4. @ (text/html media type L@ tb) 'level' media H͸ @ Ѵ.
    5. Accept-Charset c O J charset media H͸ @ ãb. c ^ٔR ISO-8859-1 ڻ\J@ xѴ. text/* media type@ Cڷ Ưr ڻ\J ʻ@ @ ISO-8859-1 rѴ.
    6. ISO-8859-1 Ƈ charset media H͸ @ Ѵ. ׷ ^ٔR, _ @ Ѵ.
    7. J ΃ȵ@ @ Ѵ. user-agent J ΃ȵ@ ٔR @ Ѵ. ׷ʽO ΃ȵ ΃ȵȵ ٔR ΃ȵȵ @ Ѵ. ΃ȵǾų ΃ȵȵ @ Ѵ.
    8. content length @ @ Ѵ.
    9. @ ù @ Ѵ. ƾb type-map H տ ԰ų, 丮݋ @ л@ Hϸ@ ASCII ȵ b݋ [ տ b ͓ƴ.
  3. ˽O '' @ ߴ. ư@ [ڷ . HTTP [ c Varyb t ȴ. (v ij{b ڿ@ ij{V r ȝ~ ] .) .
  4. Z迡 nߴٔR ( v o[ V얿) n Ó ȵ . ("No acceptable representation" [b) 406 ~ڷ ȝ~ U@ @ HTML ݋ [@ . , HTML Vary cb t.
top

ǰ] ۸[

Hġb vv Hġ ˽O@ Qݞ ŰʽO ǰ] Ѵ. Ϟb [O rȮ r ʾb v (˽O) @ ݋. θ oƾb v Ϻξb ߽o @ ø[nU Accept c . v [O ùٸ r ٔR, @ [ʾb.

Media Type ϵī

Accept: ] cb media type x t. , *b ڄPƶn ɸ[V얿 "image/*" "*/*" 'ϵī' media type@ ȝ~ ]n . E݋ ٞ @ ]@:

Accept: image/*, */*

"image/" C۸[b type ٸ typen ɸ`@ ǹѴ. vb _ ٷ ] b type ߰ ϵī带 . R:

Accept: text/html, text/plain, image/gif, image/jpeg, */*

Ϟb P type@ x[ ٸ F ٔR װ͙n M@ t ݋. v ͻ@ ٞ Cڷ ǰ@@ ȝ~ ͓ƴ.

Accept: text/html, text/plain, image/gif, image/jpeg, */*; q=0.01

P type@ ǰ] ^݋ ⺻@ ( @) 1.0@ . ϵī */*b @ xn 0.01@ Ƿ P type ¾b ^b 쿡 ٸ type ȝ~ȴ.

Accept: c q ] ^O "*/*" ٔR, Hġb ٶ ൿ@ q @ڷ 0.01@ rѴ. , "type/*" ϵī忡b ("*/*"پb x[nU) 0.02 rѴ. Accept: c݋ q ] b media type ٔR Ʒ Ư @@ ߰[ ʾb. E݋ C r b v ]@ ]цη QѴ.

(language)

Hġ 2.0@ ε巴 [ ˽O ؛ ܸ  ߰ߴ.

Ŭƾh ݋L ]@V ݋L v Accept-language ¾b Z Ѱ ãڔR ^, ׵\ ʻ@ ݋Lb Ŭƾh "No Acceptable Variant" "Multiple Choices" [@ . Ʒ @ ̸[ Accept-language C[O Ŭƾh ] Ȯ b ݋ nU Hġ r ] . ForceLanguagePriority Cb ݋L Ʒ [ Ȥ@ Ѵٸ C[O LanguagePriority C ǸZ[nU Ѵ.

, ݋Lb ¾b 𽁸 oã@ θ𽁸 ã@ ]n . 齁 Ŭƾh v [b en-GB 𽁷 ݋ ] , HTTP/1.1 Fؿ R ݋Lb enڷθ FC ݋ ^ڷ ø[ oѴ. (E݋ v ظ[b ڰ ^ n ] ڹǷ Accept-Language c en-GB `[O en@ `[ʙڔR ȮǞ ߽o r@ ϞǸ[. un @ Ŭƾh@ Ʒ eڷ ⺻rǘ.) ٸ 𽁸 ã o[ ݋L "No Acceptable Variants" ų LanguagePriority ư ѴٔR, ݋Lb [ Ծ@ C[O en-GB en ݋ [Ѵ. όmڷ Hġb θ𽁸 ſ @ ǰ@ڷ Ŭƾh A~ U ߰Ѵ. ׵\ Ŭƾh "en-GB; q=0.9, fr; q=0.8"@ ][O ݋L "en" "fr" ݋ ٔR, "fr" ݋ õ@ Ǹ[. ƾb HTTP/1.1 F@ ŰO, ùٷ r Ŭƾh ȿڷ ۸[`ƴ.

ȝ~ڰ x[b 𽁸 ˾Ƴ (Ű Ư URL- @) O ^@ [ Hġ 2.0.47 mod_negotiation@ prefer-languageb ȯ溯] ΃eѴ. ȯ溯] Z[O ±׸ `ѴٔR, mod_negotiation@ ش[b @ ø[O CnѴ. ׷ ^ٔR ^ r@ CѴ.

SetEnvIf Cookie "language=(.+)" prefer-language=$1

top

ڿz\(transparent) ~ Ȯ

Hġb ٞ ڿz\ ~Ȯ @ (RFC 2295) ȮѴ. U ؛ο {encoding ..}b Ưr content-encoding@ @ ĪѴ. RVSA/1.0 ˽O@ (RFC 2296) U݋ ΃ȵ @ ΃e ] O, ΃ȵ Accept-Encoding ] c ¾b ΃ȵ n ȝ~[nU ȮǾ. RVSA/1.0 @ @ ã ǰ] ] 5ڸ݋ ^ø[ ʾb.

top

[۸r ƓĢ [

(language) @ ȝ~ѴٔR Hϻ@ \ Ȯڸ O Ȯ b݋b ^ڹǷ Hϸ \ ٸ ƓĢ@ ȝ~ ] . (ڼ ~@ mod_mime ݋ O[.)

Hϻ@ MIME-type Ȯ (, html), 쿡 encoding Ȯ (, gz), HϿ \ b Ȯڸ (, en) .

:

ٞ@ Hϸ HϿ Ϟȿ[O Ϟȿ[ʻ@ [۸r δ:

Ϟȿ [۸r Ϟȿ[ʻ@ [۸r
foo.html.en foo
foo.html
-
foo.en.html foo foo.html
foo.html.en.gz foo
foo.html
foo.gz
foo.html.gz
foo.en.html.gz foo foo.html
foo.html.gz
foo.gz
foo.gz.html.en foo
foo.gz
foo.gz.html
foo.html
foo.html.gz.en foo
foo.html
foo.html.gz
foo.gz

F R [۸r Ȯڙn ^b Ɠ@ (, foo) H ȝ~ ] @ ] . @ ݋ v Ҋ ] ݋, [Ƶ\r ]r[ʽO html H@ shtmlƳ cgi ] پb ƴ.

[۸r MIME-type@ (, foo.html) ȝ~[O ʹٔR (encoding Ȯڰ ٔR ư͙n `[) Ȯڸ MIME-type Ȯں ʿ (, foo.html.en) νѴ.

top

ij{ [

ij{ F@ v[R F ] URL@ CŲ. ٞ URL@ ][R ij{b v F@ ȝ~Ѵ. ׵\ ݋L ڿ ù偓 ] ij{ǽ ]@ ij{ ߽o [@ @ ] . Ƹ Hġb ~ ^ȯǾb ] HTTP/1.0 Ŭƾh ij{ o[nU FC Ѵ. , Hġb [ ij{ A~[b HTTP/1.1 @ Ѵ.

CacheNegotiatedDocs Cb HTTP/1.0 xȯ Ŭƾh(v Ȥ@ ij{) ] [@ ij{ ] Ѵ. Cb ݋L xzh r ȝ~[, ƱԄh ʾb. Cb HTTP/1.1 Ŭƾh ]b 谡 ^.

HTTP/1.1 Ŭƾh Hġb [ ˷־b Vary HTTP [c . r ȝ~[ ٞ ]@ ij{ ȝڷ ü ] b ǸZ ] . ^ ij{ ȝ@ ѴٔR force-no-vary ȯ溯] rѴ.

:  en  |  fr  |  ja  |  ko  |  tr 

top

Comments

Notice:
This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our mailing lists.
С͸