I’m replacing an old ASP.NET webforms app with a new MVC application. However, I have an issue with users having old links to a particular page that I would like to automatically translate to the correct MVC route.
Old site: http://mysite.com/ticketsdetail.aspx?id=12345
New site: http://mysite.com/tickets/details/12345
Is there a way in the MVC routing of catching the old url and translating it to the new one?
EDIT:
Ok, the web.config entry to do this using the IIS7 URL rewriting is:
<rewrite>
<rules>
<rule name="Ticket page redirect" stopProcessing="true">
<match url="ticketsdetail.aspx$" />
<conditions>
<add input="{QUERY_STRING}" pattern="id=(\d*)$" />
</conditions>
<action type="Redirect" url="Calls/Tickets/{C:1}" appendQueryString="false" redirectType="Temporary" />
</rule>
</rules>
</rewrite>
Don’t do it in code is my suggestion, unless you absolutely need to. Scott Hanselman has a good article on how to do what you need in the web.conf using IIS Url Rewrite.
Article Here
This would be your rule that would go in your web.config as well: