2010-05-17 76 views
71

我正在使用片段標識符爲我的web應用程序similar to this guy中的AJAX事件創建永久鏈接。喜歡的東西:URL中片段標識符的有效字符列表?

http://www.myapp.com/calendar#filter:year/2010/month/5 

我已經做了搜索的相當多,但無法找到該片段idenitifer有效字符列表。 W3C spec不提供任何東西。

我是否需要對URL中的字符進行編碼?

在這個地方似乎沒有任何好的信息。

回答

81

查看RFC 3986

fragment = *(pchar/"/"/"?") 
pchar   = unreserved/pct-encoded/sub-delims/":"/"@"  
unreserved = ALPHA/DIGIT/"-"/"."/"_"/"~" 
pct-encoded = "%" HEXDIG HEXDIG 
sub-delims = "!"/"$"/"&"/"'"/"("/")" 
       /"*"/"+"/","/";"/"=" 

所以,你可以使用!$&'()*+,;=,一些配套%[0-9a-fA-F]{2},一些配套[a-zA-Z0-9]-._~:@/?

+0

完美,我一直在尋找,在RFC,但也似乎沒有找到合適的條款。謝謝。 – sohtimsso1970 2010-05-17 14:30:10

+0

對於空格是+還是%20?角度似乎善待字面... – 2014-02-19 15:41:38

+2

@AndreaRatto'%20' – Artefacto 2014-02-20 12:33:17

28

http://tools.ietf.org/html/rfc3986#section-3.5

fragment = *(pchar/"/"/"?") 

pchar   = unreserved/pct-encoded/sub-delims/":"/"@" 
unreserved = ALPHA/DIGIT/"-"/"."/"_"/"~" 
sub-delims = "!"/"$"/"&"/"'"/"("/")" 
      /"*"/"+"/","/";"/"=" 
pct-encoded = "%" HEXDIG HEXDIG 

因此,組合,片段不能包含#,原始%^[]{}\"<根據RFC規定的>。那

+0

謝謝。對於Artefacto的答案,因爲他的髮型更快,但給了你+1的迴應。 – sohtimsso1970 2010-05-17 14:30:44

+2

我想你缺少不可打印的ASCII字符和非ASCII字符。 – Artefacto 2010-05-17 14:30:46

+0

似乎忘記了未列表中的「VERTICAL BAR(|)」和「GRAVE ACCENT(')」和「SPACE()」。因此,非列表中的可打印(7位)US-ASCII字符的完整列表爲:''「#%< > [\] ^'{|}''' – GitaarLAB 2017-11-16 16:02:38

0

另外一個RFC說話:RFC-1738

URL schemeparts for ip based protocols: 
HTTP 

httpurl  = "http://" hostport [ "/" hpath [ "?" search ]] 
hpath   = hsegment *[ "/" hsegment ] 
hsegment  = *[ uchar | ";" | ":" | "@" | "&" | "=" ] 
search   = *[ uchar | ";" | ":" | "@" | "&" | "=" ] 
相關問題