html - 如何从一个域重定向到另一个保持路径组件?

标签 html redirect blogs tumblr

我希望将一个页面从一个域(正确地说是一个子域)重定向到另一个维护相同路径组件的页面。

我正在使用博客服务,而不是运行服务器;但我可以编辑博客的global head。

我已经成功重定向到其他网站的主页:

<meta http-equiv="refresh" content="1; url=http://subdomain-2.domain.com">
<script type="text/javascript">
    window.location.href = "http://subdomain-2.domain.com"
</script>

但我无法将第一个域的任何页面重定向到第二个域中的相应页面——比如,http://subdomain- 1.example.com/post/lorem-ipsum-123http://subdomain-2.example.com/post/lorem-ipsum-123

我想知道是否可以通过编辑头部来获取当前 URL 并将目标域替换为原始域。

我想我只能使用 HTML、JavaScript 或 PHP。

最佳答案

使用 JavaScript 解决如下:

<script type="text/javascript">
    window.location.href = "http://" + "here-your-target-domain" + window.location.pathname
</script>

关键元素是 window.location.pathnameHere我找到了我需要的东西。

关于html - 如何从一个域重定向到另一个保持路径组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25878230/

相关文章:

javascript - 我们如何让循环音乐在其他页面继续播放?

html - 直接在 HTML 文件中进行 301 重定向

python - 如何从 scrapy 响应中获取 cookie 并将 cookie 设置为下一个请求?

javascript - 如何仅更改博主第一篇文章的 CSS?

php - 博客CMS的一些问题

javascript - 按钮行为异常并重新加载页面

html - 在 rails 4.2.4 的布局文件夹中产生的不同标题元素

jquery - 标题后的线条和图像,自动计算线条宽度以填充容器

apache - 在共享主机上时,如何在Apache 2中模拟和测试URL重写规则,而在.htaccess中禁用/不允许RewriteLog?

blogs - 生物信息学资源