简体   繁体   English

如何使用IIS重写模块删除URL中的锚点?

[英]How to remove an anchor in a url with IIS rewrite module?

I have this url https://example.com/test/#/anchorpart1/anchorpart2 and I want to do a redirect to https://example.com/test2 . 我有这个网址https://example.com/test/#/anchorpart1/anchorpart2 ,我想重定向到https://example.com/test2

So far I created the following rule: 到目前为止,我创建了以下规则:

<rule name="Redirect" stopProcessing="true">
          <match url=".*" />
          <action type="Redirect" url="https://example.com/test2" appendQueryString="false" redirectType="Permanent" />
        </rule>

This will lead to the following result: 这将导致以下结果:

https://example.com/test2#/anchorpart1/anchorpart2 https://example.com/test2#/anchorpart1/anchorpart2

How can I remove "#/anchorpart1/anchorpart2" to have only " https://example.com/test2 " maybe by using matching or condition rules? 如何通过使用匹配或条件规则将“#/ anchorpart1 / anchorpart2”删除为仅具有“ https://example.com/test2 ”?

The portion of the URL after # (fragment) is never passed to the server as per HTTP specification, therefor, URL rewrite won't see it. URL(#片段)之后的部分从未按照HTTP规范传递到服务器,因此,URL重写将看不到它。

To solve this issue, you can deploy a static HTML page that will take care of redirecting requests like the example bellow: 要解决此问题,您可以部署一个静态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>

By using the following solution, you will be able to escape the #(fragment) of the incoming request URL and redirect it. 通过使用以下解决方案,您将能够转义传入请求URL的#(片段)并将其重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM