简体   繁体   English

澄清HTML中的相对URL

[英]Clarification on relative URLs in HTML

From my understanding, "/" is equivalent to the base page, eg if I'm on 据我了解, "/"等同于基本页面,例如,如果我在

http://www.somesite.com/somefolder/somepage.php

and see "/" then 然后看到"/"

"/" = "http://www.somesite.com"

in that context. 在这种情况下。 To give a real-life example of my problem, I'm on http://hope.builtbymighty.com/build/directory-office.html and I see 举一个现实的例子,我在http://hope.builtbymighty.com/build/directory-office.html上 ,我看到了

<form class="head-search js-head-search" method="post" action="/">
                <label class="meta" for="head-keywords">Search term</label>
                <input type="text" id="head-keywords" name="keywords" placeholder="Search…" />
                <button type="submit">Search</button>
            </form><!-- /.head-search -->

and I want that search feature to work on my own site. 我希望该搜索功能可以在我自己的网站上运行。 So I replaced 所以我换了

action="/"

with

action="http://hope.builtbymighty.com/" 

but that's not working. 但这不起作用。 In fact, http://hope.builtbymighty.com/ doesn't even work when I try to visit that site. 实际上,当我尝试访问该站点时, http://hope.builtbymighty.com/甚至无法正常工作。 Can someone point out what I'm doing wrong here? 有人可以指出我在做什么错吗?

Also, how do you write a relative URL to the current page you're on? 另外,如何将相对URL写入当前所在的页面?

You are wrong. 你错了。 / points to the site root, that is http://www.somesite.com . /指向站点根目录,即http://www.somesite.com

If you want a relative URL to http://www.somesite.com/a/b/c.html when you are in http://www.somesite.com/a/d.html , simply use b/c.html . 如果您在进入http://www.somesite.com/a/b/c.html时想要相对URL到http://www.somesite.com/a/d.html ,则只需使用b/c.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM