如何在 ASP 中将缩短的 URL 重定向(或重写 URL)到长(原始)URL



我创建了一个功能,可以将长网址缩短为短网址。 与 bit.ly 和谷歌网址缩短器相同 例如

它缩短了 https://www.moneycontrol.com/news/india/karnataka-election-results-2018-live-updates-missing-mlas-raise-concerns-in-congress-jds-camp-2568569.html

到 http://hostname/snKcxi (http://localhost:9909/snKcxi)

我创建了一个页面,即 http://localhost:9909/shrtn.aspx 它应该从 http://localhost/snKcxi 获取 url 键值:snKcxi,然后将控制权转移到原始长 url,即如果我点击 http://localhost:9909/snKcxi 它应该重定向到:https://www.moneycontrol.com/news/india/karnataka-election-results-2018-live-updates-missing-mlas-raise-concerns-in-congress-jds-camp-2568569.html

我尝试过 URL 重写,例如:

<rewrite>
<rules> 
<!-- For URL redirect-->
<rule name="redirectRule" stopProcessing="true">
<match url="^http://localhost:9909/$" />
<action type="Redirect" url="http://localhost:9909/shrtn.aspx" redirectType="Found"/>
</rule>
</rules> 
</rewrite>

但它无法实现受人尊敬的功能。 当我点击 http://localhost/snKcxi 时,它会转到 404 错误页面! 谁能帮我?任何建议或更改??

我想做的是从短网址中获取键(我将根据键从数据库中搜索长网址) 然后将其传输到长网址

在web.config文件中添加了以下规则,问题就解决了。

<match url="^[a-zA-Z0-9]+$" />
<action type="Rewrite" url="/shrtn.aspx?id={R:0}"/>

最新更新