.NET Url rewrite the root url

会有一股神秘感。 提交于 2019-12-10 08:48:58

问题


I have the follow rule in IIS7:

    <rule name="RewriteAll" stopProcessing="true">
      <match url="^([^/]+)/?$" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{URL}" negate="true" pattern="\.axd$" />
        <add input="{URL}" negate="true" pattern="\.png$" />
        <add input="{URL}" negate="true" pattern="\.gif$" />
        <add input="{URL}" negate="true" pattern="\.jpg$" />
        <add input="{URL}" negate="true" pattern="\.css$" />
        <add input="{URL}" negate="true" pattern="\.js$" />
      </conditions>
      <action type="Rewrite" url="default.aspx?page={R:1}" />
    </rule>

That catch urls like http://mysite.com/contact/

I can't figure out with rule to use to catch http://mysite.com/ and send to for example home.aspx. Can anyone help me with the match regex


回答1:


I fixed it by adding the following rule:

 <rule name="Index Request" enabled="true" stopProcessing="true">
     <match url="^$" />
     <action type="Rewrite" url="index.aspx" logRewrittenUrl="true" />
 </rule>



回答2:


Why not just setup a canonical name (CName) on your DNS server to automatically redirect http://domain.com to http://www.domain.com?

See the CName explanation on wikipedia



来源:https://stackoverflow.com/questions/5550777/net-url-rewrite-the-root-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!