Problem with site in a subfolder

Discussion in 'Site Programming, Development and Design' started by elitemike, Jun 19, 2010.

  1. I see I'm not the only one that has this problem

    I am coming over from webhost4life and all my sites resided in subfolders with a domain name pointer simply doing it's job. I don't have a problem having to do all this manually except there doesn't seem to be any clear direction anywhere.

    I followed every blog/forum post I could find. Tried all the different techniques and still nothing. I am using ajax and I"m using ~/ a lot to get to the root of the site.

    The domain in question is sunlighttruth.com, and the application resides in the slt folder in the root.

    I have a web config file at the root level with the following rule

    Code:
                <rules>
                    <rule name="CanonicalHostNameRule1" enabled="false">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="^sunlighttruth\.com$" negate="true" />
                        </conditions>
                        <action type="Redirect" url="http://sunlighttruth.com/{R:1}" />
                    </rule>
                  <rule name="Sunlight Truth" enabled="true" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                      <add input="{HTTP_HOST}" pattern="^(www\.)?sunlighttruth\.com$" />
                      <add input="{PATH_INFO}" pattern="^/slt($|/)" negate="true" />                       
                        <!-- The following condition prevents rule from rewriting requests to .axd files -->                
                      <add input="{URL}" pattern="\.axd$" negate="true" />                    
                    </conditions>
                    <action type="Rewrite" url="\slt\{R:0}" />
                  </rule>
                </rules>
    The following outbound sits in the slt web.config

    Code:
    <outboundRules>
                    <rule name="Outgoing - URL paths" enabled="true">
                        <match filterByTags="A" pattern="^(?:slt|(.*//[_a-zA-Z0-9-\.]*)?/slt)(.*)" />
                        <action type="Rewrite" value="{R:1}{R:2}" />
                        <conditions>
                            <add input="{URL}" pattern="\.axd$" negate="true" />
                        </conditions>
                    </rule>
                    <rule name="response_location URL">
                        <match serverVariable="RESPONSE_LOCATION" pattern="^(?:slt|(.*//[_a-zA-Z0-9-\.]*)?/slt)(.*)" />
                        <action type="Rewrite" value="{R:1}{R:2}" />
                      <conditions>
                        <add input="{URL}" pattern="\.axd$" negate="true" />
                      </conditions>
                    </rule>
                    <rule name="response_location querystring">
                        <match serverVariable="RESPONSE_LOCATION" pattern="(.*)%2fslt(.*)" />
                        <action type="Rewrite" value="{R:1}{R:2}" />
                      <conditions>
                        <add input="{URL}" pattern="\.axd$" negate="true" />
                      </conditions>
                    </rule>
                </outboundRules>
    That code is supposed to remove any leading slt/ from urls.
    http://weblogs.asp.net/owscott/archive/2010/05/26/url-rewrite-multiple-domains-under-one-site-part-ii.aspx

    I am trying to make this as simple as possible, but right now I just need it to work, this is 1 of 4 sites that will be sitting in a sub folder :mad:

    We need to have a few more expamples in the url rewrite sticky. domain name to subfolder and subdomain. I'd rather not have code in my app to do a redirect, but if it's the only way, then so be it.

    Thanks for your time.
     
  2. Ray

    Ray

    It looks like you have all kinds of different rules and conditions setup. This gets really confusing and hard to diagnose.

    Try this. Start with a simple rule first and get it to work and then build from there. I suggest you start with this one rule and one condition then start building from there in complexity.

    Steps to setup the rewrite rules.
    1. Log into the server using IIS 7 Manager. If you are unsure on how to setup your IIS 7 Manager to connect to a Winhost server, refer to this kb article. http://support.Winhost.com/KB/a628/using-the-microsoft-iis-70-manager.aspx
    2. Once you are logged in go to module labeled “URL Rewrite”.
    3. Click on ‘Add Rules…’, and choose ‘Blank rule’ from the Add rule(s) window
    4. Type a name for the rule, I used ‘Rule1’.
    5. Make sure you choose ‘Matches the pattern’ in the Requested URL: drop down box and ‘Regular Expression’ in the Using: drop down box.
    6. In the Pattern text box type (.*)
    7. Click on the button ‘Add Conditions’ then under the drop down box labeled ‘Logical Grouping:’ choose ‘Match Any’ and click on the ‘Add’ button.
    8. Type {HTTP_POST} for Condition input.
    9. Type ^domainpointer\.com$ in the ‘Pattern:’ text box. Note the carrot sign ‘^’, the forward slash ‘\’, and the dollar sign ‘$’, these are regular expression symbols that you will need to add. Type the pattern just as I lay out.
    10. The rule will only look for calls that is ‘http://domainpointer.com’ and it will not filter calls that are ‘http://www.domainpointer.com’. To have the rule also encompass ‘http://www.domainpointer.com’, you will need to click on the Add button again and create the condition. You will run through steps 8 thru 9 but in the Pattern text box you will type ^www.domainpointer\.com$
    11. When the conditions are defined, you will be back in the Edit Rule window; choose ‘Rewrite’ in the ‘Action Type:’ drop down box.
    12. In the ‘Rewrite URL:’ text box type \blogengine\{R:1}
    13. Put a check mark next to ‘Append query string’.
    14. Click on the Apply link on the top right corner of the Edit Rule window. Your rule is now setup.
     
    Last edited by a moderator: Oct 14, 2015
  3. Thanks for the reply Ray,

    Yes what I posted is more complicated, it started out simple and got increasingly more complicated. I had the basic domain pointing to the subfolder working

    all those rules are designed to hide the /foldername

    You guys will be getting lots and lots of new clients from webhost4life and having multiple sites on an account is going to be common.

    A perfect write up of how to do this while maintaining ajax usability will be key to your continued expansion of clients. Not everyone wants to pay a minimum of 4.99 a month to have a basic site when it can piggyback on another.

    If I could suggest. How about a much cheaper option. Maybe 1.99 a month for no database and maybe less storage. Only offer this to those that have larger plans in place though. This is essentially what webhost4life did when you added a site.
     
  4. A "perfect" tutorial would be difficult considering the number of variables involved when you dovetail two technologies (AJAX and URL rewrite). There is not really a one-size-fits-all approach.

    I appreciate your comments about WebHost4Life and their pricing, but I don't think we are going to mimic anything that they did.
     

Share This Page