对相对 url 锚标记感到困惑
Confused about relative url anchor tag
我对锚标记中的相对 href url 感到困惑。我有一个案例:
我有一个可以通过 abc.com/it 或 abc.com/it/index[=32= 访问的主页] 与 return 相同的页面。在该页面中,我有带有 relative url href='./about' 的锚标记(在这种情况下我不能使用绝对或根相对 url) .问题是:
当我通过url访问页面时 abc.com/it/index
然后点击锚 link,它会重定向到 abc.com/it/about
(这是我的预期结果)。
但是如果我通过abc访问页面。com/it然后点击link,它
将重定向到 abc.com/about(这不是我的期望)。
任何人都请给我一个解决方案。谢谢大家
那是因为 abc.com 是您的根目录。
两个选项可以解决这个问题-
将您的根目录更改为 abc。com/it
更改您的 url href-'。/it/about
解决方案是在您的基数 URL 后添加一个斜杠,即 abc.com/it/
。
这是相关 URLs (RFC 1808)
规范中的相关行
The last segment of the base URL's path (anything
following the rightmost slash "/", or the entire path if no
slash is present) is removed and the embedded URL's path is
appended in its place.
我还建议添加从 abc.com/it
到 abc.com/it/
的重定向
我对锚标记中的相对 href url 感到困惑。我有一个案例:
我有一个可以通过 abc.com/it 或 abc.com/it/index[=32= 访问的主页] 与 return 相同的页面。在该页面中,我有带有 relative url href='./about' 的锚标记(在这种情况下我不能使用绝对或根相对 url) .问题是:
当我通过url访问页面时 abc.com/it/index 然后点击锚 link,它会重定向到 abc.com/it/about (这是我的预期结果)。
但是如果我通过abc访问页面。com/it然后点击link,它
将重定向到 abc.com/about(这不是我的期望)。
任何人都请给我一个解决方案。谢谢大家
那是因为 abc.com 是您的根目录。 两个选项可以解决这个问题-
将您的根目录更改为 abc。com/it
更改您的 url href-'。/it/about
解决方案是在您的基数 URL 后添加一个斜杠,即 abc.com/it/
。
这是相关 URLs (RFC 1808)
规范中的相关行The last segment of the base URL's path (anything following the rightmost slash "/", or the entire path if no slash is present) is removed and the embedded URL's path is appended in its place.
我还建议添加从 abc.com/it
到 abc.com/it/