http://example.com/path/to/dir/index.html
,我通过 http://proxyserver.com/path/to/dir/index.html
进行代理。同样,我希望页面中的所有相对 URL 都由 proxyserver.com
解析,而不是 example.com
。应该设置什么适当的 <base>
href 值呢?我希望页面上的相对 URL 如下:
-
newfile.html
解析为 http://proxyserver.com/path/to/dir/newfile.html
- /newfile.html
解析为 http://proxyserver.com/newfile.html
- #hash
解析为 http://proxyserver.com/path/to/dir/file.html#hash
在页面中设置 <base href="" />
可以正确地完成此工作,但它是否有一些影响?在不同的浏览器中是否有不同的解释?空的 href
值实际上意味着什么?它是否适用于所有框架,如 Angular?我听说
<base>
标签对于 Angular 应用程序来说是必需的,因此删除 <base>
标签可能无法正常工作。注意:网站可能已经包含一些
<base>
标签,我希望始终覆盖它们。我还尝试过
<base href="/" />
,但它会将相对 URL 解析为:-
newfile.html
解析为 http://proxyserver.com/newfile.html
- #hash
解析为 http://proxyserver.com/#hash
这是错误的。非常感谢您的帮助。
<base>
标签的href
空值意味着什么。它是与未设置相同还是删除现有的<base>
标签?但是,这会导致必须使用<base>
的 Angular 应用程序出现问题。 - Vaibhav Nigam