Keep old URLs when implementing UrlRewriter.net
I added UrlRewriter.net to my site today and it works fine with redirecting my SEO links to actual pages. The question is if there is any w开发者_Python百科ay to keep my old links in site and have ResolveUrl() using the rules to output links in my page. The "old" links should never be viewed by either search bots or users.
Example link in page:
<a href="<%= ResolveUrl("~/Help.aspx") %>">Help</a>
I added rewrite code like this in web.config:
<rewrite url="~/help" to="~/help.aspx" />
<rewrite url="~/help/(.+)" to="~/help.aspx?section=$1" />
First it would be great to have the links rendered without any extra job like MVC has. The second best is if there is a nice way to just add rules for "the other way" as well in the rewrite list.
This would also enable me to easally turn off/on redirecting when debugging.
Ok. I implemented the Routing tecnique used in MVC routing in my web.forms instead which allowed me to use below code:
ASPX:
<%= Url.RouteUrl("article", new { name="my-name-for-artcile"}) %>
And register all routes in one place like:
routes.MapWebFormRoute("articles", "artiklar", "~/articles.aspx");
I used the code Phil Haack made about Webform routing but modified it in a small way to get it working with master pages and also added som web.config settigns to get it working smoothly on server with non-aspx urls.
http://blog.joakimfischer.se/post/2009/11/08/Web-Form-Routing.aspx
Now it works as intended but I stoped using UrlRewriter.net to get the functionality I wanted.
精彩评论