Charles Wesley
Charles Wesley

Reputation: 829

Kentico app in sub folder and IIS URLRewrite?

I am hosting a site on winhost and I am using IIS URLRewrite to allow for sub folders on the host to be mapped to sub domains.

i.e.

~/

~/myapp/

~/KenticoCMS/

with IIS URL Rewrite rules in the root web.config to route requests for 'mydomain.com' to route to ~/KenticoCMS/ and requests for "myapp.mydomain.com' to route to ~/myapp/

Currently when I disable the rewrite, mydomain.com/KenticoCMS/ comes up fine.

However when I enable to rewrite, I get an exception:

[ArgumentOutOfRangeException: startIndex cannot be larger than length of string. Parameter name: startIndex]
System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +10698899
CMS.URLRewritingEngine.URLRewriter.CheckPermissions(String siteName, PageInfo pi, Boolean excludeSystem) +235
CMSAppBase.CheckSecurity() +775
CMSAppBase.CMSAcquireRequestState(Object sender, EventArgs e) +606
CMS.CMSHelper.CMSApplicationModule.app_AcquireRequestState(Object sender, EventArgs e) +22
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

Anyone have any suggestions on how to configure the site so that it can work in this setup?

Edited to add web.config from root folder with re-write code:

I believe, however, the issue is with the Kentico app thinking it is in a sub folder (which it is) but not getting that sub folder via the URL.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <rewrite>
      <rules>
        <rule name="Rewrite to Kentico" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^mydomain.com$" />
          </conditions>
          <action type="Rewrite" url="KenticoCMS/{R:1}" />
        </rule>
        <rule name="Rewrite to Myapp" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^myapp.mydomain.com$" />
          </conditions>
          <action type="Rewrite" url="myapp/{R:1}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

Upvotes: 2

Views: 968

Answers (1)

mnield
mnield

Reputation: 1869

so this is a pretty old question, but the short answer is that I think your assumption is correct, Kentico does not like that the URL has been altered in this way.

I have done something similar before which should be helpful if anyone else has this issue, but it does a redirect instead of a rewrite.

I setup the following rule:

<rule name="all subdomains" stopProcessing="true">
  <match url=".*" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="(myapp)\.example\.com" />
  </conditions>
  <action type="Redirect" url="http://example.com/{C:1}{URL}" redirectType="Found" />
</rule>

Obviously, you can change the redirect type etc. but the key thing is it's a redirect and not a rewrite, so it's not entirely what you're pointing at in the original question.

Assuming however that you have/had valid licence keys for the subdomains, I'm not sure why you would need or want to do this with a rewrite, as you can just setup an IIS site per subdomain.

Upvotes: 1

Related Questions