简体   繁体   中英

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 .

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

How can I remove "#/anchorpart1/anchorpart2" to have only " https://example.com/test2 " maybe by using matching or condition rules?

The portion of the URL after # (fragment) is never passed to the server as per HTTP specification, therefor, URL rewrite won't see it.

To solve this issue, you can deploy a static HTML page that will take care of redirecting requests like the example bellow:

<!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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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