We'd like to slightly alter our web.config file in different slots. For example, we'd like to redirect and proxy to different urls in different slots. I was thinking about using app settings, which can be read as env variables, but I couldn't find a way to use them in the XML. I image something like this:
<rule name="Reverse proxy" stopProcessing="true">
<match url=".*" />
<action type="Rewrite" url="{ENV_EXTERNAL_HOST}{REQUEST_URI}" appendQueryString="false" />
</rule>
That {ENV_EXTERNAL_HOST} part is of course wrong. Is it possible to use these settings from the contents of the web.config XML file?
We ended up using rewrite maps to map incoming urls to different values.
Related
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.
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.
I'm developing my first website and just learnt about the web.config file for IIS, so what I'm trying to do is to hide different parts of the url.
For example the homepage is www.domain.com/it/homepage.html and I'd love to make it appear as www.domain.com/it/homepage
I haven't found anything about removing an .html extension on the net, just a lot of .aspx which I tryed to replace with .html, failing miserably.
Another side question: is it possible to redirect errors with web.config ? I've seen a lot of .htaccess based solutions but that's it.
EDIT: Forgot to say that the website is hosted by ARUBA, on their windows oriented server
You are trying to change the URL of your site, which is the way to access it... that's a pretty odd action to do. When you get a request to your server for a certain page, the URL is parsed as the path to that file. If you want to change the URL, you need to change the name of the file - and if you wouldn't like having a .html in the end, then perhaps the file shouldn't be a html file - however, your goal is different. You want to have no extension at all.
Luckily, there is a way to have a url endpoint which doesn't have any file extension is all. That would be a folder. Folders dont have an extension to them, however they have no content by themselvs except the file they're linking.
Side note: There's another way, which is the one you'd usually see around the web. PHP could have other things in the URL than just the endpoint, but you asked about windows based HTML/ASPX windows backed pages.
So - yeah, the only way I see to have no extension at all is letting the user navigate through folders. The only question left is, why would you want this anyway?
You can use the following configuration in your web.config file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="niceURL" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}.html" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
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>
I want to ensure that anybody who goes to http://example.com/* gets automatically redirected to http://www.example.com/*. Currently, IIS allows either URL form to work, meaning that any page can be accessed at multiple URLs, which has a number of disadvantages (SEO, etc).
Is there any way to do this built into IIS (especially IIS 6) without setting up a third-party rewriting engine like this? It seems like a bazooka to kill a mosquito.
The easy way would be to simply remove the DNS entries for 'www.mysite.com', so the only DNS entries that exist are for 'mysite.com'.
Alternatively, here's a couple of techiques for redirecting to a canonical URI:
http://www.kalyani.com/2010/01/redirecting-to-canonical-url-in-iis7/
https://web.archive.org/web/20211020203216/https://www.4guysfromrolla.com/articles/072810-1.aspx
http://www.stevenhargrove.com/redirect-web-pages/
Basically you want to hand back a 301 Moved Permanently status for the non-canonical URIs, along with the canonical URI so the user agent may load it instead.
I have another solution for you:
<rule name="Canonical domain name" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$" />
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>