Kovaci
Kovaci

Reputation: 1241

Rewrite external subdomain

I have a public index.html page on the azure website:

mysite-production.azurewebsites.net

Users can set their "page name" so that when you visit

mysite-production.azurewebsites.net/pagename

it displays their page. I'm accomplishing this using rewrite rules in my web.config. Here are the two rewrite rules I currently have:

<rule name="Force HTTPS" enabled="true">
      <match url="(.*)" ignoreCase="false" />
      <conditions>
        <add input="{HTTPS}" pattern="off" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
    </rule>
    <rule name="Rewrite to index.html">
      <match url="^([0-9a-z]+)+$" />
      <action type="Rewrite" url="index.html?id={R:1}" />
    </rule>

The first your standard force https and the second allows me to dynamically load the page. So when someone goes to

mysite-production.azurewebsites.net/pagename

they actually see

mysite-production.azurewebsites.net/index.html?id=pagename

This way I can use javascript to dynamically change that index page. I also have another url:

mysite.org

that I have pointing at the azure website. I have an SSL on mysite.org and since its cleaner users use this site to go to their custom pages. Everything works great.

Now the problem is that I now have a 3rd party that wants their own url to display their custom page. They have a unique custom page we'll call custompage so that users can go to:

mysite.org/custompage

and see their custom page. Their url is a wildcard subdomain and basically looks like this:

subdomain.notmysite.org

They do NOT want any redirecting. They simply want that subdomain to display mysite.org/custompage with their subdomain displaying in the address bar. I have create the cname record and have subdomain.notmysite.org pointing at mysite-production.azurewebsites.net. So now I am trying to create a rewrite rule that will match subdomain.notmysite.org, show their custom page, but keep their url in the address bar.

Here's one of the many I've tried that I placed between the other two rules:

<rule name="Notmysite" stopProcessing="false">
      <match url=".*" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^subdomain\.notmysite\.org$"/>
      </conditions>
      <action type="Rewrite" url="{HTTP_HOST}/custompage" />
    </rule>

But I cannot figure out how to get this to work.

Upvotes: 0

Views: 44

Answers (1)

Kovaci
Kovaci

Reputation: 1241

Was able to fix it. The problem was with the "match url" part. I was matching any url when what I needed to check for was that the path after the host was empty. Here is the working solution.

<rule name="Notmysite" stopProcessing="true">
      <match url="^$" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^(www.)?subdomain\.notmysite\.org$" />  
      </conditions>
      <action type="Rewrite" url="index.html" />
    </rule>

So now, if www.subdomain.notmysite.org or subdomain.notmysite.org access my site are rewrite them to the index page and generate the content based off the url.

Upvotes: 1

Related Questions