澄清HTML中的相对URL

时间:2015-01-24 18:48:54

标签: html form-submit

根据我的理解,"/"等同于基页,例如如果我在

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

然后看"/"

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

在这种情况下。为了给出我的问题的真实例子,我在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 -->

我希望该搜索功能在我自己的网站上运行。所以我换了

action="/"

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

但那不起作用。实际上,当我尝试访问该网站时,http://hope.builtbymighty.com/甚至无效。有人能指出我在这里做错了吗?

另外,您如何编写当前页面的相对URL?

1 个答案:

答案 0 :(得分:2)

你错了。 /指向网站根目录,即http://www.somesite.com

如果您在http://www.somesite.com/a/b/c.html时想要http://www.somesite.com/a/d.html的相对网址,只需使用b/c.html