I'd like to rewrite a url to match the exact name of the file name of the page. I mean: I've a http://example.com/PagePage.aspx, and on typing on the browser bar http://example.com/pagepage.aspx I'd like to obtain again http://example.com/PagePage.aspx.
Of course, the same on typing any combination of characters, i.e. Pagepage.aspx, pagePage.aspx, and so on...
I tried in this way:
<system.webServer>
<rewrite>
<rules>
<rule name="SpecificRewrite" stopProcessing="true">
<match url="^pagepage$" />
<match url="^Pagepage$" />
<match url="^pagePage$" />
<action type="Rewrite" url="PagePage.aspx" />
</rule>
</rules>
</rewrite>
</system.webServer>
but I get "500 - Internal server error".
So I also tried in this way:
<system.webServer>
<rewrite>
<rules>
<rule name="SpecificRewrite" stopProcessing="true">
<match url="^pagepage\/?$" />
<match url="^Pagepage\/?$" />
<match url="^pagePage\/?$" />
<action type="Redirect" url="/PagePage.aspx" />
</rule>
</rules>
</rewrite>
</system.webServer>
But I get an infinite loop
I tried to obtain the same using Global.asax
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
string path = context.Request.Path;
if (path.Equals("/pagepage.aspx"))
{
context.RewritePath(path.Replace("pagepage.aspx", "PagePage.aspx"));
// or context.RewritePath("PagePage.aspx"); is the same
}
}
But, again...I get an infinite loop erro...
I googled the issue but...the methods I found are, more or less, the same I've already tried. Where am I wrong?
Any suggestion about it? Thank you in advance