asp.net - ASP.NET web.config 中的 301 重定向,包括参数

标签 asp.net redirect url-rewriting web-config

我正在考虑使用 301 重定向,因为我注意到我的域在 Google Analytics 上的一堆点击到 .asp 页面,这些页面不再存在,已将所有内容移至 .NET 设置。

花了一些时间谷歌搜索,我已经能够将以下代码添加到我的 web.config。

<location path="products.asp">
    <system.webServer>
     <httpRedirect enabled="true" destination="https://www.hartnollguitars.co.uk/products.aspx" httpResponseStatus="Permanent" />
    </system.webServer>
</location> 

这很好,可以从 products.asp 移动所有内容至 pproducts.aspx但它不保留查询字符串,这对于任何意义都是必不可少的,即 products.aspx?id=789

最佳答案

您必须添加 $Q到目标 url 以保留查询字符串。
所以在你的情况下它应该是这样的:

<location path="products.asp">
    <system.webServer>
     <httpRedirect enabled="true" destination="https://www.hartnollguitars.co.uk/products.aspx$Q" httpResponseStatus="Permanent" />
    </system.webServer>
</location> 

关于asp.net - ASP.NET web.config 中的 301 重定向,包括参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26819774/

相关文章:

asp.net - 如何将值从 .aspx 页面发送到 JavaScript 文件?

c# - ASP.net 链接按钮 PostBackUrl 不适用于 IIS 8

javascript - 动态添加 JS 到 ASP.NET 页面并从 JS 获取结果

PHP 头函数不起作用

android - 如何检查不受限制的 Internet 访问? (强制门户检测)

php - 这叫什么,我应该阅读什么才能让它发挥作用?

jquery - 迭代asp.net复选框,如果选中任何一个,则取消选中ID为="All"的复选框

javascript - 如何从 Angular route 完全删除#标签?

java - 使用 servlet 映射在 JSP 项目中隐藏 .jsp 扩展名

.htaccess - 使用 htaccess 隐藏目录