Creating subdomains in Azure - azure

We have a VM in Azure, ourserver.westeurope.cloudapp.azure.com. I need to create two subdomains, sub1.ourserver.westeurope.cloudapp.azure.com and sub2.ourserver.westeurope.cloudapp.azure.com. Both must point to the same IP as ourserver.westeurope.cloudapp.azure.com.
How do I do it?

For now, Azure does not support add subdomains.
If you want to use subdomains, maybe you can buy a domain name from domain register(third party, like register.com, godaddy.com), and map your domain name to this VM's Public IP address, then add subdomains to this public IP address.

You can also use different port numbers for each website.
Default port: 80 ourserver.westeurope.cloudapp.azure.com
Port: 8081 sub1
Port: 8082 sub2
and Etc.
To access Go to:
http://ourserver.westeurope.cloudapp.azure.com:portNumber
http://ourserver.westeurope.cloudapp.azure.com:8081 ---> sub1

I'm not sure, but MAYBE, the URL rewrite can work in this situation.
You can have different folders inside you VM's "public" folder, one for each content of the subdomain. Then, use the URL Rewrite to map each subdmain in their specific folder.
I did something similar, but wasn't for subdomains. I just pointed different domains to different folders. Here is an example of how it would be in your case (I didn't test, just guessed based on my case):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="sub1 virtual path rewrite">
<match url="^.*$" ignoreCase="false" />
<conditions>
<add input="{HTTP_HOST}" pattern="^sub1\.ourserver\.westeurope\.cloudapp\.azure$" />
</conditions>
<action type="Rewrite" url="/Sub1Folder/{R:0}" appendQueryString="true" />
</rule>
<rule name="sub2 virtual path rewrite">
<match url="^.*$" ignoreCase="false" />
<conditions>
<add input="{HTTP_HOST}" pattern="^sub2\.ourserver\.westeurope\.cloudapp\.azure$" />
</conditions>
<action type="Rewrite" url="/Sub2Folder/{R:0}" appendQueryString="true" />
</rule>
</rules>
<outboundRules>
<rule name="sub1 virtual path rewrite">
<match serverVariable="RESPONSE_LOCATION" pattern="^(https?\://ourserver\.westeurope\.cloudapp\.azure)/Sub1Folder/(.+/)$" />
<conditions>
<add input="{RESPONSE_STATUS}" pattern="^301$" ignoreCase="false" />
</conditions>
<action type="Rewrite" value="sub1/{R:1}/{R:2}" />
</rule>
<rule name="sub2 virtual path rewrite">
<match serverVariable="RESPONSE_LOCATION" pattern="^(https?\://ourserver\.westeurope\.cloudapp\.azure)/Sub2Folder/(.+/)$" />
<conditions>
<add input="{RESPONSE_STATUS}" pattern="^301$" ignoreCase="false" />
</conditions>
<action type="Rewrite" value="sub2/{R:1}/{R:2}" />
</rule>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>
I don't know if you will need to create subdomains in the domain register. Maybe you will need to, because sometimes you have to pay extra fees to have subdomains.
So, I don't know if the URL Rewrite would work without creating them. And if it works, I don't know if it's legal to do (please don't do any workaround to avoid the register fees).

Related

Windows server2012r2 how to create multiple subdomain site

I'm creating an application that accepting users as sub-domains,
Ex: {user_id}.mywebsite.com, thus, every request has to be *.mywebsite.com.
Problem is that every sub domain has to be bind on the iis
user1.mywebsite.com
user2.mywebsite.com etc etc
My question is, is there a way to set a domain site to accept every sub-domain request?
This is basically what I want to do
Is there any way to do it without adding every user as sub-domain to the iis site?
Thanks in advance.
You can set up a catch-all site and then use ARR to forward the traffic,
<system.webServer>
<rewrite>
<rules>
<rule name="site1" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(.*).site1.com$" />
</conditions>
<action type="Rewrite" url="http://localhost:8091/{R:0}" />
</rule>
<rule name="site2" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(.*).site2.com$" />
</conditions>
<action type="Rewrite" url="http://localhost:8092/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
Other supporting steps can be found in this blog post,

IIS Rewrite IP:Port to {domain}/{thing}

What I'm trying to do:
I own a domain, let's say blahblahblah.com
On the server, it points to :80 and :443 properly - this is working
I want to remap so that if a user visits blahblahblah.com/thing1 then it maps to localhost:5000
Similarly, I also want to remap so that if a user visits blahblahblah.com/thing2 then it maps to another server and port on my local network (not exposed to the internet)
I essentially want to use my webserver to communicate with other servers on my network and other ports through "sub directories" or whatever they are called in this instance (site/subdir, site2/subdir). I've been trying to solve this issue for days! I've installed ARR (and enabled the Proxy) and the URL Rewrite modules on my IIS.
I've attempted god knows how many different rewrite templates on SO. I can get partial success, in which the route /thingx/ resolves, but all the resources are referencing blahblahblah.com and (appropriately) can't find the resources for the site at that address.
Current rewrite (resolves some resources at blahblahblah.com/thing1, but others are misrouted):
<rewrite>
<rules>
<rule name="Thing1" enabled="true">
<match url="(thing1*)" />
<action type="Rewrite" url="http://localhost:5000/{R:0}" />
</rule>
</rules>
</rewrite>
EDIT: I've updated my rules to the below, as per this article from Microsoft Docs: Reverse Proxy with URL Rewrite v2 and Application Request Routing . These rewrites supposedly do exactly what I need, but the result is not the same in my case, and I still have no clue why.
<rules>
<rule name="Thing1" enabled="true">
<match url="^thing1/(.*)" />
<action type="Rewrite" url="https://localhost:5000/{R:0}" />
</rule>
</rules>
<outboundRules>
<rule name="Add application prefix" preCondition="IsHTML">
<match filterByTags="A" pattern="^/(.*)" />
<conditions>
<add input="{URL}" pattern="^/(thing1)/.*" />
</conditions>
<action type="Rewrite" value="/{C:1}/{R:1}" />
</rule>
<preConditions>
<preCondition name="IsHTML">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
More Notes:
localhost:5000 works as expected
localhost/thing1 resolves in 404 Not Found
blahblahblah.com/thing1 resolves in pulling in the default HTML page, but none of the assets (javascript, css, etc), they return 404 Not Found.
EDIT: It may be important to note that these rules have been written into the default site (bound to :80, :443) on IIS' web.config. Writing these rules in C:\Windows\System32\inetsrv\config\applicationHost.config results in a 500.
Any feedback on what I'm doing wrong?
Part of this was due to the way SPAs are handled (# and history mode), but I ended up solving with the below webconfig for IIS, which allows me to nest everything under a /foobar endpoint:
<rewrite>
<rules>
<rule name="Subdirectory Index" stopProcessing="true">
<match url="^foobar/index\.html$" ignoreCase="false" />
<action type="None" />
</rule>
<rule name="Subdirectory Routes" stopProcessing="true">
<match url="." ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="/foobar/index.html" />
</rule>
</rules>
</rewrite>

IIS Redirection 301 of a link for only one domain without affecting the links of other domains

i have two domains which share a similar link for a content that is /games-for-cats. What i want is redirecting the games-for-cats link to another link for FR website for instance but leaving the games-for-cats link untouched for other domain. I am using IIS and asp.net MVC so i tried doing this in the Web.Config but this isn't working. Below is what i tried to do.
<rules>
<rule name="Redirect rule pl for Redirects">
<match url=".*" />
<conditions>
<add input="{Redirects:{REQUEST_URI}}" pattern="(^(preprod\.test-website\.pl)(.*)$)" />
</conditions>
<action type="Redirect" url="{C:3}" appendQueryString="false" redirectType="Permanent" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="Redirects">
<add key="/games-for-cats" value="/link-to-be-redirected" />
</rewriteMap>
</rewriteMaps>
Can someone guide to what the correct rewrite rule is.
Thanks.
You need to add an additional condition to your rule which will trigger your rule for a specific domain only:
<rule name="Redirect rule pl for Redirects">
<match url=".*" />
<conditions>
<add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />
<add input="{HTTP_HOST}" pattern="^preprod\.test-website\.pl$" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" redirectType="Permanent" />
</rule>

Rewrite URL for path to domain in Azure App Service using Virtual Directory

I have set up an Azure App Service to use Virtual Directories.
The path my-app.azurewebsites.net/api is working correctly with the site wwwroot/api.
I have a CNAME record for api.mydomain.com to my-app.azurewebsites.net which works just fine as well. I can successfully call api.mydomain.com/api.
However I'd like to use a subdomain instead of the path, rewriting api.mydomain.com to api.mydomain.com/api
I've added a web.config file in my wwwroot directory which looks like following now
wwwroot/
- api/
- web.config
web.config:
<rewrite>
<rules>
<rule name="My redirection">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^api.mydomain.com$" />
</conditions>
<action type="Redirect" url="https://api.mydomain.com/api/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
After a restart, the App Service is not responsive and does not serve requests anymore. Is there a better way to achieve this or do I need to modify my rewrite?
After a few attempts I figured the mistake. Redirect has to be changed into Rewrite.
<rewrite>
<rules>
<rule name="My redirection">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="api.mydomain.com$" />
</conditions>
<action type="Rewrite" url="api/{R:1}" />
</rule>
</rules>
</rewrite>

IIS 7 URL Rewrite - CamelCase domain and lower case everything else

I am trying to setup rewrite rules for my site in iis 7 with the URL Rewrite module. If the site name is "WonderfulWidgets"
I want it to always be http://WonderfulWidgets.com.
NOT: wonderfulwidgets.com
NOT: WONDERFULWIDGETS.com
I also want everything after WonderfulWidgets.com to be lower case.
IE WonderfulWidgets.com/best-widgets.
I have accomplished the lower case url rewrite and I have also made it so it will remove any leading www before WonderfulWidgets.com
My problem is my lower case URL rewrite lowers the domain name too. I need help writing the CamelCase domain name that works with rewriting everything else as lower case.
Here's what I have in my web.config:
<rewrite>
<rules>
<rule name="CanonicalHostNameRule1">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^WonderfulWidgets\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://WonderfulWidgets.com/{R:1}" />
</rule>
<rule name="RemoveTrailingSlashRule1" stopProcessing="true">
<match url="(.*)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="Default Document URL Rewrite" stopProcessing="true">
<match url="(.*?)/?Default\.aspx$" />
<action type="Redirect" url="{R:1}/" />
<conditions>
<add input="{URL}" pattern="WebResource.axd" negate="true" />
</conditions>
</rule>
</rules>
</rewrite>
DNS names are generally treated as case insensitive, and so most (all?) web browsers display the domain name in all lower-case in the address bar. To my knowledge you cannot change this behavior via changing what you return in your HTTP response.
From RFC 4343:
According to the original DNS design decision, comparisons on name
lookup for DNS queries should be case insensitive.
From Wikipedia:
Domain names are interpreted in case-independent manner.
The browsers all seem to prefer lower-case presentation.

Resources