This code works perfectly to url rewrite 2 segments of the URL.
For example
/nottinghamshire/newark
However, if I add string t = Request.QueryString["t"].Replace("-", " ").ToLower().Replace(".aspx", "")
to the mix, meaning
/nottinghamshire/newark/plumbers
yet this works?
?r=nottinghamshire&c=newark&t=plumbers
This is my code
Web config:
<rule name="rewritereview">
<match url="^([^/] )/([^/] )?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_URI}" pattern="\.js|\.css|\.img|\.scimg" negate="true" />
</conditions>
<action type="Rewrite" url="/city.aspx?r={R:1}&c={R:2}&t={R:3}" appendQueryString="false" />
</rule>
Code behind on city.aspx.cs
string r = Request.QueryString["r"].Replace("-", " ").ToLower();
string c = Request.QueryString["c"].Replace("-", " ").ToLower().Replace(".aspx","");
string t = Request.QueryString["t"].Replace("-", " ").ToLower().Replace(".aspx", "");
if (r != null && c != null && t != null)
{
// populate page
}
else // 404?
{
}
What am I doing wrong?
CodePudding user response:
Try Updating the match URL. adding an extra "/([^/] )"
<match url="^([^/] )/([^/] )/([^/] )?$" />