HAJJAJ
HAJJAJ

Reputation: 3787

how to redirect using IIS and take the querystring?

I am trying to use URL rewriter in IIS, I have used the below role to redirect from http://mywebsite.com/panel/qr-member?id=85 TO http://mywebsite.com/MemberInfo.aspx?MemberID=85 but it did not work with me.

I followed this link to make it but no success at all enter image description here

any suggestions or help thanks and best regards

Upvotes: 0

Views: 94

Answers (1)

Jalpa Panchal
Jalpa Panchal

Reputation: 12769

You could use below URL rewrite rule:

 <rule name="rewrite test">
                <match url="(.*)" />
                <conditions>
                    <add input="{REQUEST_URI}" pattern="/panel/qr-member" />
                    <add input="{QUERY_STRING}" pattern="id=(.*)" />
                </conditions>
                <action type="Rewrite" url="/MemberInfo.aspx?MemberID={C:1}" appendQueryString="false" logRewrittenUrl="true" />
            </rule>

Code of MemberInfo.aspx page:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MemberInfo.aspx.cs" Inherits="urlexample.MemberInfo" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
      <h1>URL Rewrite Module Test Page</h1>
      <table>
            <tr>
                  <th>Server Variable</th>
                  <th>Value</th>
            </tr>
            <tr>
                  <td>Original URL: </td>
                  <td><%= Request.ServerVariables["HTTP_X_ORIGINAL_URL"] %></td>
            </tr>
            <tr>
                  <td>Final URL: </td>
                  <td><%= Request.ServerVariables["SCRIPT_NAME"] + "?" + Request.ServerVariables["QUERY_STRING"] %></td>
            </tr>
      </table>
</body>
</html>

enter image description here

Upvotes: 1

Related Questions