How to transfer the work of 301 redirects when there are parameters in the query string?

I have moved some of my old asp pages to the new aspx website. On all the old pages that I used (for example.asp file):

Response.Status = "301 Moved Permanently"; 
Response.AddHeader("Location","http://www.example.com/example.aspx");

The problem is that when the page example.com/example.asp?param=value¶m2=value2
- the redirect does not work ...

Anyone ...?

+3
source share
3 answers

This solution will work from a classic ASP page. Basically, an example of what the dalch said.

<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.test.com/default.aspx?" + Request.QueryString
Response.End
%>
+2
source

, . , Request.Url.Query.

0

You can try something like this to ensure that the query string wraps:

protected void Page_Load(object sender, EventArgs e)
{
    Response.Status = "301 Moved Permanently";
    string sQueryString = this.Request.ServerVariables["QUERY_STRING"];
    Response.AddHeader("Location", String.Format("http://www.domain.com/example.aspx?{0}",   sQueryString));
}
0
source

Source: https://habr.com/ru/post/1755963/


All Articles