为什么我们不使用这样的URL格式? [英] Why we don't use such URL formats?

查看:85
本文介绍了为什么我们不使用这样的URL格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在修改项目的URL格式.我们搜索URL的基本格式是:-

I am reworking on the URL formats of my project. The basic format of our search URLs is this:-

www.projectname/module/search/<search keyword>/<exam filter>/<subject filter>/... other params ...

在没有搜索关键字和检查过滤器的情况下进行搜索时,URL为:-

On searching with no search keyword and exam filter, the URL will be :-

www.projectname/module/search///<subject filter>/... other params ...

我的问题是,为什么我们看不到这样的URL带有反斜杠(www.projectname/module/search之后的3个斜杠)?请注意,我不再在项目中使用.htaccess重写规则.此URL在功能上完美无缺.那么,我应该使用这种格式吗?

My question is why don't we see such URLs with back to back slashes (3 slashes after www.projectname/module/search)? Please note that I am not using .htaccess rewrite rules in my project anymore. This URL works perfect functionally. So, should I use this format?

有关为什么选择此格式的更多详细信息,请检查我的其他问题:- 建议最好的URL样式

For more details on why we chose this format, please check my other question:- Suggest best URL style

推荐答案

出于兼容性和安全性的双重考虑,Web服务器通常会在应用程序看到请求之前删除多个斜杠.提供纯文件时,通常允许路径段之间的任意数量的斜杠表现为一个斜杠.

Web servers will typically remove multiple slashes before the application gets to see the request,for a mix of compatibility and security reasons. When serving plain files, it is usual to allow any number of slashes between path segments to behave as one slash.

空白URL路径段在URL中不是无效的,但通常避免使用,因为带有空白段的相对URL可能会意外解析.例如,在/module/search中,指向//subject/param的链接不是相对于文件,而是指向路径为/param的服务器subject的链接.

Blank URL path segments are not invalid in URLs but they are typically avoided because relative URLs with blank segments may parse unexpectedly. For example in /module/search, a link to //subject/param is not relative to the file, but a link to the server subject with path /param.

是否可以从原始URL中看到多斜杠序列取决于服务器和应用程序框架.例如,在CGI(以及其他基于它的网关标准)中,通常用于实现路由的PATH_INFO变量通常会省略多个斜杠.但是在Apache上,有一个非标准的环境变量REQUEST_URI,它给出了请求的原始形式,而没有像PATH_INFO这样的斜杠或进行任何%-unscaping的操作.因此,如果您希望允许使用空路径段,则可以,但是它将减少您的部署选项.

Whether you can see the multiple-slash sequences from the original URL depends on your server and application framework. In CGI, for example (and other gateway standards based on it), the PATH_INFO variable that is typically used to implement routing will usually omit multiple slashes. But on Apache there is a non-standard environment variable REQUEST_URI which gives the original form of the request without having elided slashes or done any %-unescaping like PATH_INFO does. So if you want to allow empty path segments, you can, but it'll cut down on your deployment options.

除了空字符串以外,还有其他一些字符串也不能构成良好的路径段.默认情况下,许多服务器都使用编码的/(%2F),\(%5C)或空字节(%00).因此,您不能将任何旧字符串放在段中;必须删除一些字符(通常以"slug"表示,以去除除字母和数字以外的所有字符).在执行此操作时,您也可以将_替换为空字符串.

There are other strings than the empty string that don't make good path segments either. Using an encoded / (%2F), \ (%5C) or null byte (%00) is blocked by default by many servers. So you can't put any old string in a segment; it'll have to be processed to remove some characters (often ‘slug’-ified to remove all but letters and numbers). Whilst you are doing this you may as well replace the empty string with _.

这篇关于为什么我们不使用这样的URL格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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