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

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

问题描述

我正在制作一个包含文章的网站,我需要文章友好"URL,基于标题.

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

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

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.

但是,文章标题(作为任何字符串)可以包含多个特殊字符,这些字符无法直接放入我的 URL 中.例如,我知道 ?# 需要替换,但我不知道所有其他的.

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.

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

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

推荐答案

引用 RFC 的第 2.3 节3986:

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

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  "-" / "." / "_" / "~"

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

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

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

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