iis - Canonical Redirect on the server only -


i can redirect domain.com-s on www.domain.com , it's working on server charm:

<rewrite>     <rules>         <rule name="canonical host name" stopprocessing="true">             <match url="(.*)" />             <conditions>                 <add input="{http_host}" negate="true" pattern="^www\.domain\.com$" />             </conditions>             <action type="redirect" url="http://www.domain.com/{r:1}" redirecttype="permanent" />         </rule>     </rules> </rewrite> 

but has 1 side effect - working when on testing environment, on localhost , redirects on production server.

how possible add condition work on server only?

this can achieved using second condition requesting host domain.com sub-domain:

<rewrite>     <rules>         <rule name="canonical host name" stopprocessing="true">             <match url="(.*)" />             <conditions>                 <add input="{http_host}" pattern="domain\.com$" />                 <add input="{http_host}" negate="true" pattern="^www\.domain\.com$" />             </conditions>             <action type="redirect" url="http://www.domain.com/{r:1}" />         </rule>     </rules> </rewrite> 

(note missing \ in condition , redirecttype="permanent" optional)


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -