banner



How Are Multiple Inbound Service Requests Handled By Iis

IIS URL Rewrite – Hosting multiple domains under ane site

In a shared hosting environment, information technology's a common desire to take a single IIS website that handles multiple sites with different domain names.  This saves the toll of setting up additional sites with the hoster.

At ORCS Spider web, we've supported this state of affairs for many years using ISAPI Rewrite.  Now, with URL Rewrite for IIS seven, information technology'south easier and it'south integrated right into web.config.  In this blog post I'll set out to encompass the essentials for hosting multiple domain names nether a single account using URL Rewrite.

This post assumes that you are using URL Rewrite 1.0, 1.1 or 2.0.  I'll follow-upwards in a later postal service on more advanced ways to take this further nonetheless, using the new features of URL Rewrite two.0.

Part Two will comprehend the approachable rules available in URL Rewrite two.0 to take this a step further.

Commencement, the file structure

Permit's lay out the directory construction for this example.  Assume that yous have 3 domain names.  They are: masterdomain.com, site2.com and hawaiivisit.site2.com.  You've created your directory structure like this:

image

Permit's assume that masterdomain.com was already in the root of the site and can't hands be moved.  However, site2.com and hawaiivisit.site.com need to be prepare.  Each of these folders have a website inside them.

Directing the domain name to the server

Starting time, make sure that when you browse to the website past domain name, that it resolves to the correct IP address.  This is handled at the DNS level.  Your DNS entry for site2.com and hawaiivisit.site2.com will often exist identical to masterdomain.com and are managed through your DNS provider.

Communicable the site when on the server

If you host with a web hosting company then they will take care of this.  If you host yourself, make sure to set a site binding then that the expected site processes the domain name.  If you use host headers, be sure to add the extra bindings for them.

Redirecting the site to a subfolder

Now that you take the domain name directed to the server and site, URL Rewrite comes in to direct it to a subfolder.

First, brand sure that your web host supports URL Rewrite on the server that you're hosted on.  The following assumes that it's installed and supported.

You can utilize IIS 7 Manager which gives a friendly interface for creating rules.  If you prefer to write them straight in spider web.config, I'll include the rules below.

Get-go, open up URL Rewrite:

image

I've come to adopt RegEx rules instead of wildcard rules.  I find that wildcard rules reach their limit pretty quickly.  Regular expressions can be daunting at beginning only information technology's pretty easy to selection up the basics.  Here'due south an excellent reference to get started: http://www.regular-expressions.info/reference.html

To create the dominion click on "Add Rules…".

image

Select the "Blank Rule" template and click OK.

For the name, enter your domain proper name, or whatever makes the most sense to you lot.

Match URL section

In the Match URL Section, exit the defaults to lucifer the design and Regular Expressions.  For the design, enter (.*) without the parentheses.  The "URL" is the role after the domain proper name.  i.east. www.ThisIsTheDomain.com/ThisIsTheURL.  It'due south the domain that we're interested in now, not the URL.

Conditions

The Atmospheric condition section is where we'll do most of the work.  Expand that department if information technology'south collapsed and click "Add".

The domain proper noun is contained within the HTTP header chosen {HTTP_HOST}.  Here'south where the fun comes.  The regular expression pattern that will lucifer world wide web.site2.com or site2.com (without the www) looks like this: ^(www.)?site2.com$.

Here's what that means.

  • The ^ is the character that signifies the start of the string.  That ensures that something.world wide web.site2.com doesn't also go included with this rule.
  • The $ is the character that marks the finish of the string.
  • ( ) parentheses are used to create section groups.
  • ? means that something is optional.
  • Therefore, (www.)? ways that with www. or without, either are accepted.

After filling in these fields you should have something like the following:

image

Now, here's the office that many people wouldn't guess at commencement.  Since URL Rewrite works on the URL just, while virtually code (ASP.Internet, ASP, PHP, etc) works at the server level, they aren't aware of each other.  Just considering you rewrite the URL doesn't hateful that the lawmaking has any clue of the alter.  Every bit a consequence, any time that ASP.NET automatically creates the path, it will probable disharmonism with the URL Rewrite rule.  For example, Response.Redirect("~/") volition redirect to the root of the application.  That means that it can create a path like www.site2.com/site2.  Find the actress site2 in the path.  The login page for ASP.Cyberspace will mess with you likewise.

A hereafter blog post will comprehend how to hide the /site2 using URL Rewrite 2.0, but the piece of cake solution is to ensure that world wide web.site2.com and www.site2.com/site2 both go to the same identify.  Both should be served from …\masterdomain.com\site2.  It means that the URL can be longer than you may adopt, but it allows the site to keep to function.

To accomplish this, add together an exclusion status and then that this rule doesn't redirect at all if the URL starts with /site2/.

There are two ways to achieve this.  You could go back to the URL department where we previously entered .* and update that section.  At that place isn't anything wrong with that at all.  For no item reason that I can think of right now, I prefer to do this from the atmospheric condition section.  Here's how to exercise it:

Add together another status where the status input is {PATH_INFO}, and set the dropdown to "Does Not Match the Pattern", and set the Design to ^/site2/.  That means that the PATH_INFO must start with /site2/.  Note that you shouldn't stop with the $ this time because y'all want sub-sub folders to work also.  It should look similar this:

image

Activity Section

Nosotros're nigh done.  In the Activeness section, first set the "Action Type" to Rewrite. Then ready the Rewrite URL to \site2\{R:0} and ensure that the "Append query string" checkbox is checked.  The {R:0} is a back reference to the URL.  Information technology will allow the URL to be carried through dynamically in the request.  The Append query string ensures that the query string itself will carry through.

The complete rule should await similar this:

image

That's it.  Relieve and test.

Using a Text Editor

Yous may prefer to use a text editor or to see the config directly.  The dominion generated for web.config looks like this:

              <              rewrite              >            
              <              rules              >            
              <              rule              name              ="site2.com"              stopProcessing              ="true"              >            
              <              match              url              =".*"              />            
              <              conditions              >            
              <              add              input              ="{HTTP_HOST}"              pattern              ="^(www.)?site2.com"              />            
              <              add              input              ="{PATH_INFO}"              pattern              ="^/site2/"              negate              ="true"              />            
              </              weather              >            
              <              action              blazon              ="Rewrite"              url              ="\site2\{R:0}"              />            
              </              rule              >            
              </              rules              >            
              </              rewrite              >            

And, the rule for hawaiivisit.site2.com is like.  It looks like this:

              <              rewrite              >            
              <              rules              >            
              <              dominion              name              ="hawaiivisit.site2.com"              stopProcessing              ="true"              >            
              <              lucifer              url              =".*"              />            
              <              conditions              >            
              <              add              input              ="{HTTP_HOST}"              blueprint              ="^hawaiivisit.site2.com$"              />            
              <              add together              input              ="{PATH_INFO}"              pattern              ="^/hawaiivisit/"              negate              ="true"              />            
              </              conditions              >            
              <              activeness              type              ="Rewrite"              url              ="\hawaiivisit\{R:0}"              />            
              </              rule              >            
              </              rules              >            
              </              rewrite              >            

The other things

I wanted to briefly mention what isn't covered in this web log post that you may desire to consider.

  • DNS. The 'how to' for your domain proper name purchase and directing isn't covered here.
  • Statistics. If you use  a client-side choice similar Google Analytics and so this volition piece of work but as well under a single business relationship.  Still, if you lot are using a log based statistics program like SmarterStats then it's upwards to you to set up rules in SmarterStats to filter out or sub-divide the statistics into useful sections i.e. 1 per site.
  • Email. Yous volition likely need to setup another mail account with your host, or add the new domain as a domain alias to your existing account.
  • ASP.NET inheritance. web.config inherits down the unabridged path simply the ASP.Net folders practise not inherit past application boundaries.  More on that hither.  Ane workaround if ASP.Internet inheritance fights with y'all is to not accept a site in the website root.  Instead, place all sites in their ain subfolder.
  • Y'all'll probable need to marking the folder equally an application and so that information technology is an ASP.NET application.  (assuming ASP.NET of class)

Happy URL Rewriting!

How Are Multiple Inbound Service Requests Handled By Iis,

Source: https://weblogs.asp.net/owscott/iis-url-rewrite-hosting-multiple-domains-under-one-site

Posted by: taylorshum1960.blogspot.com

0 Response to "How Are Multiple Inbound Service Requests Handled By Iis"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel