制作网址的安全字符是什么? [英] What are the safe characters for making URLs?

查看:82
本文介绍了制作网址的安全字符是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作包含文章的网站,并且我需要这些文章具有友好"的含义,网址,基于标题.

例如,如果我文章的标题是"Article Test" ,我希望URL为 http://www.example.com/articles/article_test .

但是,文章标题(与任何字符串一样)可以包含多个特殊字符,而这些字符不能按原样放在我的URL中.例如,我知道需要替换?#,但是我不知道其他所有内容.

URL中允许使用哪些字符?什么是安全的?

解决方案

引用 RFC3986 :

URI中允许的但没有保留的字符目的,称为无保留.这些包括大写和小写字母,十进制数字,连字符,句号,下划线和波浪号.

  ALPHA DIGIT-"/."./"_"/〜" 

请注意,与旧版 RFC 2396 相比,RFC 3986列出的保留标点符号更少./p>

I am making a website with articles, and I need the articles to have "friendly" URLs, based on the title.

For example, if the title of my article is "Article Test", I would like the URL to be http://www.example.com/articles/article_test.

However, article titles (as any string) can contain multiple special characters that would not be possible to put literally in my URL. For instance, I know that ? or # need to be replaced, but I don't know all the others.

What characters are permissible in URLs? What is safe to keep?

解决方案

To quote section 2.3 of RFC 3986:

Characters that are allowed in a URI, but do not have a reserved purpose, are called unreserved. These include uppercase and lowercase letters, decimal digits, hyphen, period, underscore, and tilde.

  ALPHA  DIGIT  "-" / "." / "_" / "~"

Note that RFC 3986 lists fewer reserved punctuation marks than the older RFC 2396.

这篇关于制作网址的安全字符是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆