我有此网址https://example.com/test/#/anchorpart1/anchorpart2,我想重定向到https://example.com/test2。
到目前为止,我创建了以下规则:
<rule name="Redirect" stopProcessing="true">
<match url=".*" />
<action type="Redirect" url="https://example.com/test2" appendQueryString="false" redirectType="Permanent" />
</rule>
这将导致以下结果:
https://example.com/test2#/anchorpart1/anchorpart2
如何使用匹配或条件规则删除“#/ anchorpart1 / anchorpart2”以仅使用“https://example.com/test2”?
答案 0 :(得分:2)
#(片段)之后的URL部分永远不会按照HTTP规范传递给服务器,因此,URL重写将无法看到它。
要解决此问题,您可以部署一个静态HTML页面来处理重定向请求,如下例所示:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0;url=https://example.com/test2">
</head>
<body>
<script language="javascript">
window.location.href = "https://example.com/test2"
</script>
</body>
</html>
通过使用以下解决方案,您将能够转义传入请求URL的#(片段)并重定向它。