URL中的前导斜杠有什么影响? [英] what is the effect of leading slash in URL?

查看:96
本文介绍了URL中的前导斜杠有什么影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面中有:


< base href =" http://www.simple-nude.com/">


以后想要引导访问者,比如说,

http://www.simple-nude.com/today/hippie-goddess/15b.jpg


似乎链接文本可以读作以下任何一种:


< a href =" /today/hippie-goddess/15b.jpg"或者

< a href =" today / hippie-goddess / 15b.jpg">


第一个表单包含一个前导斜杠,第二个表单是不是。


这两种形式完全可以互换吗?在所有条件下,他们总是有

完全相同的效果吗?如果没有,那么这两种形式之间的有效差异是什么?


谢谢!


- fredo

解决方案

fredo写道:


[snip]


< base href =" http://www.simple-nude.com/">



[snip]


< a href =" / today / hippie-goddess / 15b .JPG"或者

< a href =" today / hippie-goddess / 15b.jpg">



[snip]


这两种形式完全可以互换吗?



不一定。它取决于基本URL。


它们在所有条件下总是具有完全相同的效果吗?



No.


如果没有,那么这两种形式之间的有效区别是什么?



路径中的前导斜杠是指根目录。也就是说,

基本网址

http://www.example.com/foo/bar


网址


/ baz


解析为:

http://www.example.com/baz


相比之下,网址


baz


将决定:

http://www.example.com/foo/baz

您使用基本元素明确设置的基本URL使得

形成更多 - 或者更少,但只是因为您选择的URL。


Mike




Michael Winter写道:


路径中的前导斜杠指的是根目录。也就是说,

基本网址

http://www.example.com/foo/bar


网址


/ baz


解析为:

http://www.example.com/baz


相比之下,网址


baz


将决定:

http://www.example.com/foo/baz



我仍​​然感到困惑。第二个例子不会涉及:

http: //www.example.com/foo/bar/baz


,如您的示例所示,基本网址:

http://www.example.com/foo/bar


谢谢,迈克。


- fredo


fredo写道:


Michael Winter写道:



[snip]

< blockquote class =post_quotes>
>相比之下,URL


将解决:

http://www.example.com/foo/baz



我还是很困惑。第二个例子不会涉及:

http: //www.example.com/foo/bar/baz


,如您的示例所示,基本网址:

http://www.example.com/foo/bar



不,因为bar是一个资源(例如一个文件)而不是一个目录(如果我意味着后者,我会给b $ b添加一个尾随斜杠)。


也许如果我已经写过:

http://www.example.com/foo/bar.html


作为基本网址,以及


baz.html


作为要解决的相对地址,本来会更清楚

http://www.example.com/foo/baz.html


会是结果吗?如果是这样,请记住扩展意味着URL中没有任何内容,并且使用规范URL(路径

到目录应始终以a结尾)是个好主意比如斜线。


Mike


I have in my page:

<base href="http://www.simple-nude.com/">

and later want to direct a visitor to, say,

http://www.simple-nude.com/today/hippie-goddess/15b.jpg

It seems that the link text can read as either of:

<a href="/today/hippie-goddess/15b.jpg" or
<a href="today/hippie-goddess/15b.jpg">

First form contains a leading slash, second form does not.

Are these two forms perfectly interchangeable? Do they always have
exactly the same effect under all conditions? If not, then what is the
effective difference between the two forms?

Thanks!

-- fredo

解决方案

fredo wrote:

[snip]

<base href="http://www.simple-nude.com/">

[snip]

<a href="/today/hippie-goddess/15b.jpg" or
<a href="today/hippie-goddess/15b.jpg">

[snip]

Are these two forms perfectly interchangeable?

Not necessarily. It depends on the base URL.

Do they always have exactly the same effect under all conditions?

No.

If not, then what is the effective difference between the two forms?

A leading slash in a path refers to the root directory. That is, with a
base URL of

http://www.example.com/foo/bar

the URL

/baz

is resolved as:

http://www.example.com/baz

In contrast, the URL

baz

would resolve to:

http://www.example.com/foo/baz
The base URL you''ve set explicitly using the base element makes either
form more-or-less interchangeable, but only because of the URL you chose.

Mike



Michael Winter wrote:

A leading slash in a path refers to the root directory. That is, with a
base URL of

http://www.example.com/foo/bar

the URL

/baz

is resolved as:

http://www.example.com/baz

In contrast, the URL

baz

would resolve to:

http://www.example.com/foo/baz

I''m still confused. Would not the second example refer to:

http://www.example.com/foo/bar/baz

given, as in your example, the base URL:

http://www.example.com/foo/bar

Thanks, Mike.

-- fredo


fredo wrote:

Michael Winter wrote:

[snip]

>In contrast, the URL

baz

would resolve to:

http://www.example.com/foo/baz


I''m still confused. Would not the second example refer to:

http://www.example.com/foo/bar/baz

given, as in your example, the base URL:

http://www.example.com/foo/bar

No, because bar is a resource (a file, for example) not a directory (I''d
have added a trailing slash if I''d meant the latter).

Perhaps if I''d have written:

http://www.example.com/foo/bar.html

as the base URL, and

baz.html

as the relative address to be resolved, it would have been more clear that

http://www.example.com/foo/baz.html

would have been the result? If so, just remember that extensions mean
nothing in URLs, and that it''s a good idea to use canonical URLs (paths
to a directory should always end with a slash, for example).

Mike


这篇关于URL中的前导斜杠有什么影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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