通过代码将多个域添加到一个Web应用程序

I have a PHP App running on my Azure. I want my customers to be able to use my application on their own domains. Is it possible to add multiple domains to one single web application? Is there an API or something to add domains to a web app programatically?

I have a web.config file that looks like below but it doesn't redirect.

<?xml version="1.0"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Rewrite domain requests" stopProcessing="true">
  <match url="(.*)" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^(www.)?([.a-zA-Z0-9]+)$" />
  </conditions>
  <action type="Rewrite" url="http://www.cemiltokatli.com/url={R:1}" appendQueryString="true" />
</rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

For that, you need to move your web app to the shared/standard mode and:

1) configure url rewriting (like described here)

2) configure multiple domain names using Site.HostNames property. That property can be used for setting additional domains. Unfortunately, i have no PHP code snippet, but working C# code is below (implemented using SDK). And, again, unfortunately, but it looks like the official Azure PHP SDK does not provide the same functionality. The way here would be to write a REST API wrapper using, for example, the snippet below as a reference. If there is no possibility from your side to execute the code and catch the request, i can do that a little later, if that will help.

public const string base64EncodedCertificate = "ManagementCertificateValueFromPublishSettingsFile";
public const string subscriptionId = "AzureSubscriptionId";

static SubscriptionCloudCredentials getCredentials()
{
    return new CertificateCloudCredentials(subscriptionId, new X509Certificate2(Convert.FromBase64String(base64EncodedCertificate)));
}
static void Main(string[] args)
{
    WebSiteManagementClient client = new WebSiteManagementClient(getCredentials());

    WebSpacesListResponse n = client.WebSpaces.List();
    n.Select(p =>
    {
        Console.WriteLine("webspace {0}", p.Name);
        WebSpacesListWebSitesResponse websitesInWebspace = client.WebSpaces.ListWebSites(p.Name,
              new WebSiteListParameters()
              {
              });
        websitesInWebspace.Select(o =>
        {
            Console.Write(o.Name);     

            return o;
        }).ToArray();
        return p;
    }).ToArray();

    Console.ReadLine();
    var configuration = client.WebSites.Get("WebSpaceName", "WebSiteName", new WebSiteGetParameters());

    configuration.WebSite.HostNames.Add("new domain");
    var resp = client.WebSites.Update("WebSpaceName", "WebSiteName", new WebSiteUpdateParameters() { HostNames = configuration.WebSite.HostNames });
    Console.WriteLine(resp.StatusCode);
    Console.ReadLine();
}

If I do not misunderstand your question, you want to manage multiple domains directing to your one Azure Web App application. E.G. manage domain1.com and domain2.com to the same yourapp.azurewebsites.net.

You can let your customer to add a CName of your azure application on his own DNS manage server. enter image description here

Then, scale up your application's app service plan to at leaset share tier. And in CONFIGURE tab of your Azure Web App's portal page, under domain names section, add yor custom's domain into the list. E.G. enter image description here

Any further concern, please feel free to let me know.