# 在 URL 中，\`my\` 是用户的通用标识。主机名是否有类似的概念？

**URL:** https://meta.discourse.org/t/with-urls-my-is-generic-for-user-is-there-something-similar-for-hostname/154542
**Category:** Support
**Created:** [2020 年6 月 11 日 15:58 UTC](https://meta.discourse.org/t/with-urls-my-is-generic-for-user-is-there-something-similar-for-hostname/154542 "2020-06-11T15:58:05Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://meta.discourse.org/u/EricGT)
#### Post date: [2020 年6 月 11 日 15:58 UTC](https://meta.discourse.org/t/with-urls-my-is-generic-for-user-is-there-something-similar-for-hostname/154542/1 "2020-06-11T15:58:05Z")

</div>

作为管理员，我们经常需要向用户发送指向其设置页面的链接。

与其提供一个 URL 中包含硬编码用户名的示例，例如

```plaintext
https://swi-prolog.discourse.group/u/ericgt/preferences/account

```

我们可以将 `u/ericgt` 替换为 `my`

```plaintext
https://swi-prolog.discourse.group/my/preferences/account

```

然后将此链接提供给用户，他们通常不会察觉其中的区别。

现在，我们中的一些管理员在访问其他网站并协助其他管理员时，希望也能实现类似的“魔法”，但这次是针对主机名，例如 `swi-prolog.discourse.group`。

在 Discourse 站点中，是否存在一个通用的主机名替换方案？

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [2020 年6 月 11 日 17:16 UTC](https://meta.discourse.org/t/with-urls-my-is-generic-for-user-is-there-something-similar-for-hostname/154542/2 "2020-06-11T17:16:13Z")

</div>

不如使用像 `/my/preferences/account` 这样的 URL

[在此处链接](https://meta.discourse.org/my/preferences/account)

```plaintext
[在此处链接](/my/preferences/account)

```

---

<div class="post-metadata">

### Author: ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://meta.discourse.org/u/EricGT)
#### Post date: [2020 年6 月 11 日 17:20 UTC](https://meta.discourse.org/t/with-urls-my-is-generic-for-user-is-there-something-similar-for-hostname/154542/3 "2020-06-11T17:20:36Z")

</div>

我在另一个网站上测试过，效果符合预期。😀

* * *

**编辑**

我花了一点时间才理解它是如何工作的，后来发现它使用的是 [绝对路径引用](https://stackoverflow.com/q/3127223/1243762)。以前从未想过可以这样做。得把这个工具加入我的工具箱了。

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [2020 年7 月 11 日 17:29 UTC](https://meta.discourse.org/t/with-urls-my-is-generic-for-user-is-there-something-similar-for-hostname/154542/4 "2020-07-11T17:29:13Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
