簡體   English   中英

如何使用IIS重寫模塊刪除URL中的錨點?

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

我有這個網址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 ”?

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的#(片段)並將其重定向。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM