sub domain [Answered]RSS

10 replies

Last post Aug 13, 2009 10:21 PM by ruslany

  • sub domain

    Jul 28, 2009 02:38 PM|Rippo|LINK

    Hi I have static rules set up but would like to include the domain for example

    <RULE name="Rewrite rules for Category Rewrites">
      <MATCH url=".*">
      <CONDITIONS>
        <ADD pattern="(.+)" input="{Category Rewrites:{REQUEST_URI}}"></ADD>
      </CONDITIONS>
      <ACTION type="Rewrite" url="{C:1}" appendQueryString="false"></ACTION>
    </RULE>

    and in my rewite maps I would like

    <REWRITEMAPS>
      <REWRITEMAP name="Category Rewrites">
        <ADD value="/BrowseCategory.aspx?CategoryId=1034&amp;ChannelId=100" key="http://www.guru.co.uk/Banking"></ADD>
        <ADD
    value="/BrowseCategory.aspx?CategoryId=1034&amp;ChannelId=200" key="http://sub.guru.co.uk/Banking"></ADD>

    etc...  Obviously this does not work. My question is how do I include domains/sub domains in my rewrite paths..... Thanks Rippo

    HTH
    Rippo
    http://www.wildesoft.net
  • Re: sub domain

    Jul 28, 2009 03:29 PM|Rippo|LINK

    I think I have solved it.... Can somebody tell me if this is the correct approach.. Many Thanks

    <rule name="sub domain 1">
      <
    match url="(.*)" />
      <
    conditions>
        <
    add input="{HTTP_HOST}" pattern="www\.guru\.co\.uk" />
        <
    add input="{Category Rewrites for Channel 100:{REQUEST_URI}}" pattern="(.*)" />
      </
    conditions>
      <
    action type="Rewrite" url="{C:0}/{R:0}" appendQueryString="false"/>
    </
    rule>

    <rule name="sub domain 2">
      <
    match url="(.*)" />
      <
    conditions>
        <
    add input="{HTTP_HOST}" pattern="it\.guru\.co\.uk" />
        <
    add input="{Category Rewrites for Channel 200:{REQUEST_URI}}" pattern="(.*)" />
      </
    conditions>
      <
    action type="Rewrite" url="{C:0}/{R:0}" appendQueryString="false"/>
    </
    rule>

    <rewriteMaps>
      <
    rewriteMap name="Category Rewrites for Channel 100">
        <
    add key="/Banking" value="/Test.aspx?CategoryId=1034&amp;ChannelId=100" />
        <
    add key="/Sales" value="/Test.aspx?CategoryId=1044&amp;ChannelId=100" />
      </
    rewriteMap>
      <
    rewriteMap name="Category Rewrites for Channel 200">
        <
    add key="/Banking" value="/Test.aspx?CategoryId=1034&amp;ChannelId=200" />
        <
    add key="/Sales2" value="/Test.aspx?CategoryId=1054&amp;ChannelId=200" />
      </
    rewriteMap>
    </
    rewriteMaps>


     

     

    HTH
    Rippo
    http://www.wildesoft.net
  • Re: sub domain

    Jul 28, 2009 03:54 PM|Rippo|LINK

    If this is the way forward then I see that the querystring now contains

    CategoryId=1044&ChannelId=100%2fSales
    or
    CategoryId=1054&ChannelId=200%2fSales2

    How do I remove the %2fSales etc from the end of the querystring?

    If I just use url="{C:0}" then I find that none of my *.js or *.css gets processed...

    As it stands url="{C:0}/{R:1}" then page is rendered but the query string has %2fSales2 on the end.

    Obviously I am in a mess! Can anyone help?

    HTH
    Rippo
    http://www.wildesoft.net
  • Re: sub domain

    Jul 28, 2009 08:13 PM|ruslany|LINK

    You can use url="{C:0}" and filter out the js and css files so that they are not affected by these rewrite rules. Try changing both rules to look as below:

    <rule name="sub domain 2">
      <
    match url="(.*)" />
      <
    conditions>
        <add matchType="IsFile" negate="true" />
        <add matchType="IsDirectory" negate="true" />
        <
    add input="{HTTP_HOST}" pattern="it\.guru\.co\.uk" />
        <
    add input="{Category Rewrites for Channel 200:{REQUEST_URI}}" pattern="(.*)" />
      </
    conditions>
      <
    action type="Rewrite" url="{C:0}" appendQueryString="false"/>
    </
    rule>

  • Re: sub domain

    Jul 29, 2009 02:31 AM|Rippo|LINK

    Excellant, Thanks Ruslany. I missed these "matchtypes". Is there a good read on this. I have gone through your blogs and examples but probably need to look into this in more depth.... This gets me out of my first hole! Again many thanks
    HTH
    Rippo
    http://www.wildesoft.net
  • Re: sub domain

    Jul 29, 2009 02:39 PM|ruslany|LINK

  • Re: sub domain

    Aug 05, 2009 08:45 AM|Rippo|LINK

    Hi Ruslany,

    I am having trouble with 404's and the above domain, basically if I have:-

    http://it.guru.co.uk/[ANYNAME]
    or
    http://it.guru.co.uk/[ANYNAME].[ANYEXTENSION].

    These ARE files/dirs that don't exist and are not defined in the rewrites.confiig file.

    It appears to be routing any 404 back to my root page and is not being caught in my global.asax file. I know the above rule is catching all 404 pages as when I comment this out in web.config then the error in my Global.asax page gets fired, however when the above is in my web.config then the event int global.asax does not get fired...

     I basically want global.asax to catch this 404 and handle appropriately myself..

    Can you help? Thanks Rippo

    HTH
    Rippo
    http://www.wildesoft.net
  • Re: sub domain

    Aug 07, 2009 01:03 PM|ruslany|LINK

    Try changing the condition as follows (note the "+" in the regex pattern):

     <add input="{Category Rewrites for Channel 200:{REQUEST_URI}}" pattern="(.+)" />
     

    If rewrite map does not find the key, it returns an empty string, which causes your rule to rewrite to the root page. Changing the pattern as above will ensure that rule will apply only if rewrite map returned non-empty string.

  • Re: sub domain

    Aug 10, 2009 06:11 AM|Rippo|LINK

    Thanks Ruslany, that has fixed it. It also has fixed another problem where my axd files were getting thrown in the mix!
    HTH
    Rippo
    http://www.wildesoft.net
  • Re: sub domain

    Aug 13, 2009 10:27 AM|Rippo|LINK

    Hi Ruslany

    One last problem.... We would like to put tracking code on a newsletter e.g.

    http://it.guru.co.uk/general-business-advice-doing-business-in-russia/?utm_source=newsletter&utm_medium=email&utm_campaign=guru-export-issue2

    However the url is not matched, Can you help again?
    Sorry to be a pain but so far you have been extremley helpful!

    HTH
    Rippo
    http://www.wildesoft.net
  • Re: sub domain

    Aug 13, 2009 10:21 PM|ruslany|LINK

    If you use rewrite map and it contains an entry for "/general-business-advice-doing-business-in-russia/" then the URL with query string will not match. The look up in the rewrite map is literal and not pattern based. If you want to exclude the query string from the rewrite map lookup then use {URL} server variable instead:

    <add input="{SomeRewriteMap:{URL}}" pattern="(.+)" />