How would one redirect from www.example.com/section/index.aspx to www.example.com/section using rewrite rules in web.config? It would also have to w开发者_如何学Goork for various levels such as www.example.com/parent/child
*Noting that I do not have access to the server. I can basically just edit the web.config file and tell the server to rebuild the application.
Your best bet is to use the IIS7 URL Rewrite Module - but you would need to install this on the server. It's pretty easy to use and powerful at the same time. It may already be installed if you're hosted, because although it's not installed by default, it is from Microsoft and pretty frequently used.
If you're on 2.0 or greater of asp.net, you can add a urlMappings
section to the web.config:
<system.web>
<urlMappings enabled="true">
<add url="~/Section" mappedUrl="~/Section/index.aspx"/>
</arlMappings>
</system.web>
But this has some issues : Firstly, if the URL requested isn't handled by the ASP.Net module, or isn't delivered to your application, the rewrite never happens. This could occur because you aren't hitting a ".aspx" file, for example. Also, in some configurations, the file you request needs to exist. Another issue is that there are no wildcard rules supported, so you would have to add rules to rewrite all possible paths individually.
And finally, there are asp.net rewrite httpmodules you could drop in the bin directory and add to your web.config. Here's some (possibly outdated) options by ScottGu for url rewriting.
This is probably massively disgusting but by creating rules for each possible level I was able to rewrite all paths dropping index.aspx from the url.
starting with
<rule name="Migrate to PHP">
<match url="^([_0-9a-z-]+).aspx"/>
<action type="Redirect" redirectType="Permanent" url="/"/>
</rule>
and ending with
<rule name="Migrate to PHP all the way">
<match url="^([_0-9a-z-]+)/([_0-9a-z-]+)/([_0-9a-z-]+)/([_0-9a-z-]+)/([_0-9a-z-]+).aspx"/>
<action type="Redirect" redirectType="Permanent" url="{R:1}/{R:2}/{R:3}/{R:4}"/>
</rule>
精彩评论