Url Rewriting with IIS 6/7 - Rewriting the host name {HTTP_HOST}

I need to rewrite "Host Name" {HTTP_HOST} for an incoming request. Is it possible to do this using the IIS 7 rewriting module?
I want to rewrite http://abc.xyz.com/ * to http://xyz.com/sites/abc/ *. This is done for a SharePoint site that internally uses {HTTP_HOST}.

Do I have Url Rewriters that allow me to modify the {HTTP_HOST} IIS variable?

Yours faithfully,

+6
source share
6 answers

I am not familiar with the Rewrite IIS 7 module, but ISAPI_Rewrite can practically change any HTTP header you want. There is a free version, which is enough for our site and may well be enough for you.

+2
source

You can use the Rewrite 2.0 URL module for IIS 7 to change the HTTP_HOST server variable. Additional information on how to do this is available in Configuring HTTP Request Headers and IIS Server Variables .

+9
source

Yes, you can use the IIS 7 rewrite module. You can use the graphical interface to configure redirection in IIS7 for this blog post .
You can also use the command line for this SO response .
In both of these examples, you should have a separate website setup with your home directory and domain bindings that you want to redirect. Hope this makes sense.

+3
source

IIRF is free and allows you to rewrite headers, including HTTP_HOST.

I want to rewrite http://abc.xyz.com/ * to http://xyz.com/sites/abc/ *. This is done for a SharePoint site that internally uses {HTTP_HOST}.

You need to rewrite both Host and Url. This makes it a little harder. In this rule set, I do this step by step and use the new header to store the state between the steps:

# detect whether we're using the abc host RewriteCond %{HTTP_HOST} ^abc\.xyz\.com$ RewriteHeader Host-Needs-Rewrite: ^$ YaHuh # rewrite the Host: header to the alt host name if necessary RewriteCond %{HTTP_HOST_NEEDS_REWRITE} ^YaHuh$ RewriteCond %{HTTP_HOST} ^(?!xyz\.com)(.+)$ RewriteHeader Host: .* xyz.com # rewrite the Url to the appropriate place RewriteCond %{HTTP_HOST_NEEDS_REWRITE} ^YaHuh$ RewriteCond %{HTTP_HOST} ^xyz\.com$ RewriteRule /(.*)$ /sites/abc/$1 [L] 

You can also customize the abc part. Like this:

 # detect whether we're using the abc host RewriteCond %{HTTP_HOST} ^([^.]+)\.xyz\.com$ RewriteHeader Host-Needs-Rewrite: ^$ %1 # rewrite the Host: header to the alt host name if necessary RewriteCond %{HTTP_HOST_NEEDS_REWRITE} ^.+$ RewriteCond %{HTTP_HOST} ^(?!xyz\.com)(.+)$ RewriteHeader Host: .* xyz.com # rewrite the Url to the appropriate place RewriteCond %{HTTP_HOST_NEEDS_REWRITE} ^(.+)$ RewriteCond %{HTTP_HOST} ^xyz\.com$ RewriteRule /(.*)$ /sites/%1/$1 [L] 
+3
source

If you want to avoid redirection (for your comment on Eugene), server.transfer is the only option. With server.transfer, processing is sent to another page on the server, and the client has no idea (there is no feedback from the client between the pages).

Besides the actual server.transfer redirects, the typical ISAPI_Rewrite is a popular tool and works very well, as Eugene noted.

+1
source

UPDATE: this will do a redirect, not a reset variable. I will not delete this answer as I think it is neat, but it does not answer exactly what you want

I make it very easy for Economist.com

You have two IIS sites for one site, they have the same website. The main IIS website remains the same as listening to the current host header, for example.

 216.35.68.215 economist.com 

and another IIS site listens for the IP address with the other headers entered.

i.e.

 216.35.68.215 economist.co.uk 

The second web slave in the Home Directory has a set of redirects that will correct any host name that people come to your site to

Set "Exact URL Above" and "Permanent Redirection for this Resource" and enter your full hostname entry as follows

http://www.economist.com $ S $ Q

$ S $ Q will support all the URLs of your other host names.

Feel free to test this

http://www.economist.co.uk/world/americas/

just push you to

http://www.economist.com/world/americas/

This means that you do not need to run, at least for this reason, the rather expensive IIS rewrite module

0
source

All Articles