asp.net - WebConfig URL Rewrites in IIS -


have asp.net solution , want achieve 2 things: -

  1. redirect www.mydomain.com mydomain.com
  2. have friendly urls

so ... here have added system.webserver section of webconfig...

 <rewrite>       <rules>         <rule name="remove www prefix" >           <match url="(.*)" ignorecase="true" />           <conditions trackallcaptures="false">             <add input="{http_host}" pattern="^www\.mydomain\.com" />           </conditions>           <action type="redirect" url="{mapprotocol:{https}}://mydomain.com/{r:1}" redirecttype="permanent" />         </rule>         <rule name="homepage" stopprocessing="true" >           <match url="^/wwwzone/homepage.aspx$"/>           <action type="redirect" url="/"/>         </rule>       <rule name="homepagereal" stopprocessing="true" >         <match url="^/$"/>         <action type="rewrite" url="/somepath/homepage.aspx"/>       </rule>       </rules>       <rewritemaps>         <rewritemap name="mapprotocol">           <add key="on" value="https"/>           <add key="off" value="http"/>         </rewritemap>       </rewritemaps>     </rewrite> 

this fails. logic behind is: -

  • first rule takes care of redirecting www.mydomain.com mydomain.com. works. , rewritemap handles http/https correctly.
  • the second rule supposed browser redirect if request unfriendly (real) url.
  • the last 1 designed convert friendly url real url, rewrite not redirect.

any thoughts appreciated.

it turns our poor syntax in regular expressions.

so, matching real url of home page should have been

<match url="^$"/> 

not

<match url="^/$"/> 

and subsequent rule rewrite real url should change in same way.

so, completeness, 1 works...

<rewrite>       <rules>         <rule name="remove www prefix" >           <match url="(.*)" ignorecase="true" />           <conditions trackallcaptures="false">             <add input="{http_host}" pattern="^www\.mydomain\.com" />           </conditions>           <action type="redirect" url="{mapprotocol:{https}}://mydomain.com/{r:1}" redirecttype="permanent" />         </rule>         <rule name="homepage" stopprocessing="true" >           <match url="^wwwzone/homepage.aspx"/>           <action type="redirect" url="/"/>         </rule>       <rule name="homepagereal" stopprocessing="true" >         <match url="^$"/>         <action type="rewrite" url="/somepath/homepage.aspx"/>       </rule>       </rules>       <rewritemaps>         <rewritemap name="mapprotocol">           <add key="on" value="https"/>           <add key="off" value="http"/>         </rewritemap>       </rewritemaps>     </rewrite> 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -