【问题标题】:How I can get the first subdomain of target site in a proxy which use plain urls如何在使用纯 url 的代理中获取目标站点的第一个子域
【发布时间】:2015-01-03 01:36:19
【问题描述】:

如果有人想要当前站点的最后一个子域(例如:getftpinftp.kernel.org,可以使用

location.hostname.split('.')[0]

但是,使用非混淆代理,URL 可以像这样http://www.someproxy.com/somepath_layers/site.bin?http://ftp.kernel.org/pub/iso
然后,location.hostname会返回代理地址。location.pathname会剥离目标地址,所以我只看到一个普通的location.href

重点是在http:// 之后剥离,但如果代理也可以安全访问,则 URL 变为https://www.someproxy.com/somepath_layers/site.bin?http://ftp.kernel.org/pub/iso

那么,在 JavaScript 中包含的最后一个模式出现之前,我如何才能匹配? (目的是让网站在 web.archive.org liveweb 中运行)。

更新:我还需要正则表达式在没有代理的情况下工作(直接访问网站时)

【问题讨论】:

  • 每个代理都有不同的语法,我不认为你可以制定一个普遍的规则。
  • @Barmar :我在我的问题中说过,我想让事情只适用于 web.archive.org 或重复目标站点完整 URL 的代理,如 thisthis

标签: javascript regex url uri


【解决方案1】:

这个正则表达式提取第一个子域:

/(?!(?:https?|ftps?):\/\/)\b([a-z][^.]+).*/ig

子域在捕获组 1 中

See regex

【讨论】:

  • 我想我应该和location.href.match()一起使用它不是吗?您的链接返回wwwwithhttps://www.someproxy.com/somepath_layers/site.bin?http://ftp.kernel.org/pub/iso而不是ftp
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-25
  • 1970-01-01
  • 1970-01-01
  • 2017-01-26
  • 2014-06-29
  • 1970-01-01
相关资源
最近更新 更多