URL Rewrite not executed on Azure, several projects - azure

I am trying to rewrite the URL on an Azure MVC application. The solution contains many projects, thus has web.config files all over the place.
The URL Rewrite objective is to send all URLs based on the Project "Statistics" to the subdomain "admin", whatever subdomain was called at the origin of the request. (I created this rule independently on my laptop with IIS Manager and imported it manually in one of the projects)
<configuration>
<system.webServer>
<!--Something here. The rule nests at the end of the block. -->
<rewrite>
<rules>
<rule name="Statistics">
<match url="[0-9a-zA-Z-]*.mysite.com/statistics/(.*)" />
<action type="Rewrite" url="https://admin.mysite.com/statistics/{R:1}" />
</rule>
</rules>
</rewrite>
</configuration>
</system.webServer>
So, I am wondering why this rule doesn't seem to be executed:
Is the syntax correct?
In which web.config file should I place this rule, considering that I have five projects in the Solution?

Related

Using emsserver/emsserver.dll in URL of API Call in Production Environment

I have created an application that utilizes RAD Studio's EMS Server functionality. The development has been completed and tested in a production environment. The EMS Server documentation shows that in order to make an API call the emsserver.dll needs to be included in the URL.
https://{hostname}/emsserver/emserver.dll/API/Login?token={TokenValue}
Most APIs I have encountered do not have the dll embedded into the URL.
https://{hostname}/API/Login?token={TokenValue}
This is not a big deal as the API call works fine as is. I was just wondering if there is property or setting I can use in RAD Server or IIS in order to default the emsserver/emsserver.dll portion of the URL.
Do you mean you want to redirect or rewrite the url from https://{hostname}/API/Login?token={TokenValue} to https://{hostname}/emsserver/emserver.dll/API/Login?token={TokenValue} in IIS?
If this is your reuqimrent, I suggest you could try to use url rewrite extension to achieve your reuqirement.
You could install it from this url and add below url rewrite rule into your web.config file.
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to dll">
<match url="API/Login" />
<action type="Rewrite" url="https://{hostname}/emsserver/emserver.dll/API/Login" />
</rule>
</rules>
</rewrite>
</system.webServer>

Add a hostname to a specific folder within Azure as another domain

So I have a project in azure that is www.example.com and it has it's MVC file structure with source code and all. However, within that, I have another part that needs it own URL, www.example2.com which would point to a folder within this hierarchy. So you could reach this entry point from www.example.com/#/example2.html or simply from going to www.example.com. Hope that makes sense. So within Azure, how can I achieve this? I am looking through custom domain, but not seeing a way to go about this. Any ideas please?
Yes, using rewrite rules in your web.config. Adjust variables accordingly.
<rewrite>
<rules>
<rule name="Redirect domain" enabled="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)?example2\.com$" />
</conditions>
<action type="Rewrite" url="folder/{R:1}" />
</rule>
</rules>
</rewrite>
Don't forget to add and authorize both domains to your web app.

It it possible to have ARR working without a matching service/website on the ARR machine itself?

I am not sure if I am missing something, but I'd really like to have it work like a routing rules table.
However it appears that if I have a service on a farm machine, then the same service should expose the same endpoints on the ARR machine.
I am not sure why thats really needed or what am doing wrong.
Its rather silly. So if I have farm with some application, first of all it has to be deployed to ARR machine, otherwise I get all kinds of 503, 500, 404 etc errors due to services/webpages not being available on the machine where ARR is setup.
For starters, ensure that the "proxy" feature is enabled...
IIS Home -> Application Request Routing -> Server Proxy Settings -> Enable Proxy
Then add rewrite rules to web.config as follows:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="AppProxy1" stopProcessing="true">
<match url="app1/(.*)" />
<action type="Rewrite" url="http://appserver:8080/{R:1}" />
</rule>
<rule name="AppProxy2" stopProcessing="true">
<match url="app2/(.*)" />
<action type="Rewrite" url="http://appserver:8081/{R:1}" />
</rule>
<!-- add more apps here -->
</rules>
</rewrite>
</system.webServer>
</configuration>
Make sure that the rewrite rules contain absolute URLs, (including http://). This key step signals ARR to run in "proxy" mode.
Additionally, you may need to rewrite outbound HTML links depending on your configuring. More information on that and using ARR as a reverse proxy in general can be found here:
http://www.iis.net/learn/extensions/url-rewrite-module/reverse-proxy-with-url-rewrite-v2-and-application-request-routing
But the basic idea is listed above.

web.config 301s for all files but one

I'm trying to set up 301s for a site which will bounce all old pages to the homepage (it was a large site that is now a single page).
The server's Windows based, however, so no htaccess fun for me.
Could anybody assist with producing a web.config file that redirects everything to the homepage via 301s?
This may work:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="301 Redirect Everything To Home" stopProcessing="true">
<match url=".+" />
<action type="Redirect" url="/" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
But is will redirect everything, including images, include files etc.
Could you explain your motive for this as generally it's a bad move. It causes a poor user experience, robots don't like it, and nothing knows if a page is really missing or not.
I suggest you to try "IsapiRewrite" 3rd party module/DLL
ISAPI_Rewrite is a powerful regular-expressions-based URL rewriter for
IIS. It is compatible with Apache mod_rewrite making it possible to
move configurations from Apache to IIS and vice versa just by copying
.htaccess files (please see this compatibility chart). It is used for
search engine optimization, to proxy another server's content, stop
hotlinking or strengthen server security.

IIS - Mapping one extension to another

I did a bit of search but can't find a complete answer to my question:
I wonder if it's possible to set my IIS 7.5 to map one "custom" extension to another "physical" extension.
Eg.
I have Default.aspx, I'd like my server to serve this file to a request of Default.foo.
The mapping questions/answers I found are all about having Default.foo files, and mapping them to the proper handler; that's not my case, I just like to have a sort of masking of the real physical file extension.
Is it possible?
TY
The mapping should be setup between default.foo and default.aspx, mapping extensions cannot achieve this goal. You may use URL Rewrite module to create a rule to rewrite default.foo to default.aspx.
A simple example is as below,
<rewrite>
<rules>
<rule name="foo" stopProcessing="true">
<match url="(.*)\.foo" />
<action type="Rewrite" url="{R:1}.aspx" />
</rule>
</rules>
</rewrite>

Resources