Reputation: 573
I'm trying to write a rewrite rule for web.config file so that the url will remove the file name from it, meaning:
http://www.example.com/admin/Index.aspx
http://www.example.com/admin/Product.aspx
will become:
http://www.example.com/admin/
http://www.example.com/admin/
AND:
http://www.example.com/Index.aspx
http://www.example.com/Product.aspx
to:
http://www.example.com/
http://www.example.com/Product/
tried a couple of codes found online, but all of them gave me internal error.
Thanks in advance!
Upvotes: 2
Views: 3596
Reputation: 571
I have used the open source UrlRewriter to do that on a number of projects, it works very well
In order to make it work you must add it to your web.config file, like so:
<httpModules>
<add type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" name="UrlRewriter" />
</httpModules>
And add a routing section as well, they have good documentation, but basically you provide rewrite-rules, that could look something like this:
<rewriter>
<rewrite url="~/([a-zA-Z0-9]+)$" to="~/$1.aspx" />
</rewriter>
Add the UrlRewriter dll-files to your bin, and set IIS to handle wildcards:
And you are done :)
It's quite a good solution for WebForms projects, but make sure you test it well, and verify that GoogleBot can still access your site.
Upvotes: 4
Reputation: 8288
im not sure if you have it but with IIS7 there is a module that you can install that you can set up url rewriting rules. It will add the appropriate rules to the web.config of your site
a guide by Scott Guthrie of Microsoft may help - http://weblogs.asp.net/scottgu/archive/2010/04/20/tip-trick-fix-common-seo-problems-using-the-url-rewrite-extension.aspx
Upvotes: 0