问题
I am rewriting some of sites in MVC.
I am concerned about old links out there, some I know about and some I don't.
I am looking for suggestions and code sample on how to make sure that my known and unknown links are not dead. What are your choices?
I would eventually like to phase out my old links. I hope to do this by notifying my users coming from old links about the new links.
I want to start off with something simple, as I am still learning MVC.
Another post suggested Managed Fusion URL Rewriter and Reverse Proxy.
回答1:
I am the developer of the URL Rewriter you mentioned. If you would like help, please contact me as suggested in the ReadMe.txt file. What you are asking for is not out of the ordinary and can be easily accomplished using some very basic rules.
Well you brought up two important points. You want to notify your users about the new links, you biggest user your probably care about at this time is Google. You can address this concern with Google by doing a 301 Permanent Redirect
. For example, this is how you would do it with the URL Rewriter syntax.
RewriteRule ^/(old-url.*)$ /new-url$1 [R=301]
The R=301
does the permanent redirect. The second your known and unknown links. For your known links you just need to map them to the correct part of your new application using the above rules. Depending on how many old url's you have you probably want to make the rewrite rule generic so one will catch many old url's.
For the unknown links you probably want to do one of two things, look over your server logs or analytics for anything important, and map those as appropriately to the correct part of your new code.
Then to make sure all the others don't totally go away you can redirect them to either your home page, internal site search, or just a generic page explaining that your site has been updated and this link is no longer in use.
Again please contact me with questions. The Managed Fusion URL Rewriter and Reverse Proxy will work perfectly with any .NET website (including MVC) on IIS 6 and any type of website on IIS 7 including PHP, Ruby, JSP, and Classic ASP.
回答2:
Have a look at this article - http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
SUMMARY:Tip/Trick: Url Rewriting with ASP.NET.
http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx
SUMMARY:Blog - ASP.NET MVC Framework (Part 2): URL Routing.
回答3:
If what you need is pretty URLs (or Search Engine Optimized), you can do it without rewriting your application. Check out URL Rewrite Module for IIS 7:
http://www.iis.net/extensions/URLRewrite/
It is Microsoft supported and supports URL rewriting and also response content rewriting (to fix your application links for example).
Daniel Vasquez Lopez.
来源:https://stackoverflow.com/questions/1320041/what-is-a-fairly-easy-to-implement-url-rewriter-for-asp-net-mvc