我希望将一个页面从一个域(正确地说是一个子域)重定向到另一个维护相同路径组件的页面。
我正在使用博客服务,而不是运行服务器;但我可以编辑博客的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-123
到 http://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.pathname
。 Here我找到了我需要的东西。
关于html - 如何从一个域重定向到另一个保持路径组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25878230/