What i understand about Url rewriting and redirect is (please point out my wrong assumptions)
by using "redirect" option for url http://localhost/Search/VehicleDetails.aspx?id=2
to transform it into http://localhost/Search/2/VehicleDetails.aspx
,when client browse http://localhost/Search/VehicleDetails.aspx?id=2
and our redirect rule changes into http://localhost/Search/2/VehicleDetails.aspx
,the server tries to find VehicleDetails.aspx page inside /Search/2
folder.
but by using "rewrite" option for url http://localhost/Search/VehicleDetails.aspx?id=2
to transform it into http://localhost/Search/2/VehicleDetails.aspx
,when client browse http://localhost/Search/VehicleDetails.aspx?id=2
, client browser displays http://localhost/Search/2/VehicleDetails.aspx
,but internally in server request is made in VehicleDetails.aspx page of Search directory ,not in VehicleDetails.aspx of /Search/2 directory...
and my problem is ,i tried to rewrite url by following rule
<rewrite>
<rules>
<rule name="Search" stopProcessing="true">
<match url="^.*(?:Search/VehicleDetails.aspx).*$" />
<conditions>
<add input="{QUERY_STRING}" pattern="id=(\d+)" />
</conditions>
<action type="Rewrite" url="/Search/{C:1}/VehicleDetails.aspx" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>
</rewrite>
it redirects to /Search/2/VehicleDetails.aspx
page with HTTP 404.(The resource cannot be found.)
.I want that client browser shows http://localhost/Search/2/VehicleDetails.aspx
but request is made on /Search/VehicleDetails.aspx
..
And also how do i get values of id (2 in this example) for the url like
http://localhost/Search/2/VehicleDetails.aspx
by Request.QueryString["id"]??
You need to select the Append QueryString
checkbox in IIS or add this manually, for example: -
<action type="Rewrite" url="/Search/{C:1}/VehicleDetails.aspx"
redirectType="Permanent" appendQueryString="true" />
I noticed you have this set to False
which will be why the ID is not being carried over and is probably the reason for the 404 too.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.