Archive for the 'URLRewrite' tag

Using Azure Web Site as a reverse proxy

IIS has been supporting reverse proxy configuration since URL Rewrite and Application Request Routing modules were released a few years ago. It is possible to configure an IIS hosted web site to act as a reverse proxy and forward web request to other URL’s based on the incoming request URL path. This is described in details in Reverse Proxy with URL Rewrite v2 and Application Request Routing.

Not too many people know however that the same kind of configuration can be achieved with a web site hosted in Azure Web Sites. This blog post explains the configurations steps to enable that.

For example if I want to forward all the requests that come to http://ruslany.net/proxy/ to some other URL I’ll need to do two things:

  1. Enable proxy functionality in ARR
  2. Add a proxy rewrite rule

Continue Reading »

14 Comments »

ruslany on May 16th 2014 in URLRewrite, WAWS

22,838 views

PoorFairAverageGoodExcellent (4 votes, average: 4.00 out of 5)

Azure Web Sites – block web access to non-production deployment slots

Windows Azure Web Sites supports Staged Publishing functionality, which allows you to create a staging site slot where you can publish a new version of the website and then test it before swapping to the production environment. By default the non-production deployment slot has its own hostname that you use to test the bits deployed there. Sometimes, however you may want to prevent users from browsing to your non-production deployment slot while you are testing it.

It is relatively easy to configure your site to block the http request if it is deployed to any non-production slot. For example let’s say I have a site ruslany.azurewebsites.net and I created a deployment slot for it and name the slot as ‘staging‘ (it is possible to give custom names to deployment slots now). The hostname for that deployment slot will be ‘ruslany-staging.azurewebsites.net‘. So to prevent access to the deployment slot from anybody except a few allowed IP addresses I can add the following rewrite rule to my site’s web.config file:

<rule name="Block unauthorized traffic to staging sites" stopProcessing="true">
<match url=".*" />
<conditions>
<!-- Enter your staging site host name here as the pattern-->
<add input="{HTTP_HOST}" pattern="^ruslany\-staging\." />
<!-- Enter your white listed IP addresses -->
<add input="{REMOTE_ADDR}" pattern="123\.123\.123\.1" negate="true"/>
<!-- Add the white listed IP addresses with a new condition as seen below -->
<!-- <add input="{REMOTE_ADDR}" pattern="123\.123\.123\.2" negate="true"/> -->
</conditions>
<action type="CustomResponse" statusCode="403" statusReason="Forbidden"
statusDescription="Site is not accessible" />
</rule>

When the site with this rule is located in my staging slot any http request to it will be blocked with HTTP 403 response as long as it is not a request from a white-listed IP address in the rewrite rule. When the site is swapped into the production slot the rewrite rule will be no-op because the first rewrite condition will not match, so all http traffic will be allowed to the site.

No Comments »

ruslany on April 24th 2014 in URLRewrite, WAWS

10,042 views

PoorFairAverageGoodExcellent (2 votes, average: 4.50 out of 5)

RuslanY.net running on Windows Azure Web Sites

I have not been writing any blog posts for a while. That was because for the past two years I have been busy working in a team that develops the Windows Azure Web Sites – a scalable web hosting platform in Windows Azure.

Now that the Windows Azure Web Sites (WAWS) is publicly available I decided to try to move my site from private hosting  to Windows Azure. My site uses WordPress (with MySql database), PHP 5.3, WinCache object and user cache, URL rewriting and many WordPress plugins. With all these different technologies (many of which are not developed by Microsoft), I thought it would be a good test of how WAWS is capable of running web sites that use open source technologies. Plus I expect that my site will be more reliable and available, comparing to my previous private hosting.

I was pleasantly surprised that the migration from private hosting to WAWS hosting was relatively quick and simple. The site has been running successfully in a Shared compute mode for a while now and none of the site’s functionality has been lost or altered. In this post I’ll explain the steps I took to move my site to WAWS hosting. Hopefully it will be useful to those who are planning to migrate their WordPress based site to WAWS. Continue Reading »

6 Comments »

ruslany on October 22nd 2012 in PHP, URLRewrite, WAWS, WinCache, WordPress

77,081 views

PoorFairAverageGoodExcellent (2 votes, average: 5.00 out of 5)

Storing URL rewrite mappings in a separate file

When using rewrite maps in IIS URL Rewrite it is very common to have a very large number of entries in a rewrite map. In order to avoid cluttering the configuration file - web.config - with this configuration data the rewrite maps can be defined in a separate configuration file. That file can then be referenced from the web.config file. This post provides an example of how this can be done.

Create a file called rewritemaps.config in the same directory where web.config file is. Open that file in notepad and add the following:

<rewriteMaps>
  <rewriteMap name="Redirects">
    <add key="/oldurl" value="/newurl" />
    <add key="/otheroldurl" value="/othernewurl" />
  </rewriteMap>
</rewriteMaps>

Save this file and then open web.config file in notepad. In the web.config file add the following inside of the <rewrite> section:

<rewriteMaps configSource="rewritemaps.config" />

The configSource attribute tells IIS configuration that the <rewriteMaps> section is defined in a separate file rewritemaps.config. This referenced section can be now uses as if it was defined in the same web.config file. Also, the IIS Manager UI will work well with this referenced file: when you modify or add entries to the rewrite map they will be stored in the rewritemaps.config file.

Here is a complete example web.config file that uses the rewrite map from referenced configuration file:

<configuration>
<system.webServer>
  <rewrite>
    <rewriteMaps configSource="rewritemaps.config"><rewriteMaps>
    <rules>
      <rule name="Redirect rule1 for Redirects">
        <match url=".*" />
        <conditions>
          <add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />
        </conditions>
        <action type="Redirect" url="{C:1}" appendQueryString="false" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>
</configuration>

The same approach can be used for storing rewrite rules in a separate configuration file, e.g.:

<rules configSource="rewriteRules.config" />

30 Comments »

ruslany on May 19th 2010 in URLRewrite

93,156 views

PoorFairAverageGoodExcellent (6 votes, average: 5.00 out of 5)

Visual Studio XML IntelliSense for URL Rewrite 2.0

Last year I published an XML schema for URL Rewrite 1.1 that could be used to enable IntelliSense support when editing rewrite rules in Visual Studio XML editor. Now that the URL Rewrite 2.0 has been released, the old schema will not work for the the new configuration elements introduced in the v2.0. Use the link below to download the schema for URL Rewrite 2.0:

VS IntelliSense for URL Rewrite 2.0

Disclaimer: The schema file and the helper script file contained in this package are provided by me and not by Microsoft. They are not officially supported by Microsoft. Use them at your own risk.

Follow the same instructions as in Visual Studio XML IntelliSense for URL Rewrite 1.1 to add the schema to the Visual Studio schema cache. If after following the instructions the IntelliSense does not work then follow the instructions at Not getting IntelliSense in your web.config for system.webServer sections in Visual Studio 2008?.

28 Comments »

ruslany on April 23rd 2010 in URLRewrite

31,765 views

PoorFairAverageGoodExcellent (9 votes, average: 4.89 out of 5)

Time-dependent URL rewriting

This post explains how to configure time-dependent URL rewriting rules by using IIS URL Rewrite 2.0. Time-dependent URL rewriting may be useful when you want to rewrite or redirect HTTP requests based on the time of day or when you need to take the entire site or some parts of the site offline for a scheduled period of time.

The rewrite rules are not time-aware, but it is relatively easy to add the time-dependent functionality by using URL Rewrite 2.0 extensibility. Follow the steps below to add a scheduler rewrite provider for URL Rewrite module. Continue Reading »

1 Comment »

ruslany on April 4th 2010 in URLRewrite

9,475 views

PoorFairAverageGoodExcellent (5 votes, average: 4.20 out of 5)

IIS URL Rewrite 2.0 – Release to Web

The IIS URL Rewrite Module 2.0 – RTW is available for download. IIS URL Rewrite v2.0 is an incremental release that includes all the features from version 1.1, and adds extensibility support and outbound response rewriting. More specifically, v2.0 can be used to:

  • Express complex URL rewriting logic by using custom rewrite providers written in .NET.
  • Replace the URLs generated by a web application in the response HTML with a more user friendly and search engine friendly equivalent
  • Fix up the content of any HTTP response by using regular expression pattern matching.
  • Modify HTTP request and response headers and IIS server variables.

For the complete list of features available in this version, refer to Using URL Rewrite Module 2.0.

Install the URL Rewrite 2.0 – RTW

To install the URL Rewrite 2.0, use the download links at the module’s home page at http://www.iis.net/expand/urlrewrite. Note that this is a final, production ready release that is officially supported by Microsoft.

Upgrade notes:

  • If a previous version of URL Rewrite Module, such as v1.0 and v1.1, is already installed then it will be upgraded to the v2.0;
  • If an RC version of the URL Rewrite Module 2.0 is already installed, then it will be upgraded to RTW version. Continue Reading »

27 Comments »

ruslany on March 11th 2010 in URLRewrite

10,165 views

PoorFairAverageGoodExcellent (11 votes, average: 3.55 out of 5)

5 Comments »

ruslany on November 9th 2009 in URLRewrite

8,230 views

PoorFairAverageGoodExcellent (6 votes, average: 4.33 out of 5)

2 Comments »

ruslany on October 6th 2009 in PHP, URLRewrite

8,897 views

PoorFairAverageGoodExcellent (5 votes, average: 3.40 out of 5)

30 Comments »

ruslany on August 13th 2009 in URLRewrite

52,867 views

PoorFairAverageGoodExcellent (10 votes, average: 4.30 out of 5)

Recently Published Articles