How to configure IIS Url Rewrite - iis

I'm trying to achieve wildcard hostname mappings in IIS 8.5. As they don't exist, I'm trying to use URL Rewrite.
I have two formats of URL,
<anything>-foo.mydomain.com
<anything>-bar.mydomain.com
I want to map these to two different sites in IIS, for example
<anything>-foo.mydomain.com --> foo.mydomain.com/<anything>
<anything>-bar.mydomain.com --> bar.mydomain.com/<anything>
I'm trying to configure a URL Rewrite rule at the machine level, but I've got some problem.
If I set it to Redirect it works. If I set it to Rewrite I get an IIS 404.4.
Can anyone shed any light on this?
Here are my settings:
http://cl.ly/a6tK

You can only rewrite the URL to the same site and same application pool. For example:
http://foo.com/bar to http://foo.com/
You need to install Application Request Routing and enable Proxy. Then it will work with URL rewriting to remote servers (regardless where or what they are) since the routing will take care of that.
http://www.iis.net/downloads/microsoft/application-request-routing

Related

IIS Rewrite rule to rewrite to different web site

I have 2 web sites installed on the same IIS server. I need them both to listen on port 443 with HTTPS. I want them to use different application pools and be able to stop and start one without affecting the other. The clients of these websites are not able to configure the host header that they use in their HTTP requests.
Is there a solution? I have been trying to use IIS Rewrite rules. I have one website deployed on port 443 and the other on some unusual port. I tried setting up a URL rewrite on the first one that did a rewrite (not a redirect) to an absolute URL referencing the 2nd site on the unusual port. This always seems to produce an HTTP 404 response.
I can't do a redirect because the client gets redirected to the unusual port and the client is not allowed to make internet requests to non-standard ports.
I believe I am using IIS 6.2, that's what is says in the Help about in IIS MAnager
What options do I have?
It is not possible to rewrite to different applications in IIS, especially if they are in different application pools. Your only option is redirect if you want to do it simply using URL Rewrite.
Another alternative is to use ARR (Application Request Routing) and then proxy the call to the actual site depending on rules, this has also the advantage that sites could be in different machines or in the same one, and give you more flexibility. Obviously it does come with more complexity.

Avoid rewriting URL's to external applications with reverse proxy on IIS?

Confluence IIS Reverse Proxy Setup
I have set up a reverse proxy on IIS 7.5 for Atlassian Confluence according to instructions found in the internet.
I wanted to redirect all traffic to "docs.unimaze.com" to "localhost:8090" on the same server.
This is how I did it:
Installed URL Rewrite 2.0
Installed Application Request Routing 3.0
Set up a reverse proxy rule:
Match URL: Matches the pattern (.*) using regular expressions (ignore case)
Conditions: (none)
Server variables: (none)
Action: Rewrite with http://localhost:8090/{R:1} (append to query string and stop processing of subsequent rules.
The only other thing I had to in order to make everything work (from https://serverfault.com/questions/76013/iis6-vs-iis7-and-iis7-5-handling-urls-with-plus-sign-in-base-not-querystr) was to run this command on the server so that URL's with "plus signs" in the URL's would be allowed.
%windir%\system32\inetsrv\appcmd set config "WebSiteName"
-section:system.webServer/security/requestFiltering -allowDoubleEscaping:true
Problem with external redirects
Confluence itself, seems to work perfectly BUT when attempting to edit a module from an external application (LucidChart Diagrams it fails), because a redirection to the external application also is rewritten, e.g. an attempt is made to redirect to this URL:
http://docs.unimaze.com/documents/edit/4b157fd9-8e28-4d70-8587-0fdd0839fbca?callback=...
when the redirect should actually be to the external application, so it should remain untouched by the rewriting rule:
https://www.lucidchart.com/documents/edit/4b157fd9-8e28-4d70-8587-0fdd0839fbca?callback=...
Is there an easy way to solve this?
This here helped: appcmd.exe set config -section:system.webServer/proxy /reverseRewriteHostInResponseHeaders:"False" -commit:apphost
In UI, the setting corresponding to this action on the Application Request Routing in IIS on the server node (select „Server Proxy Settings“) should be unchecked.
However, this had the effect that the page can not be loaded in Internet Explorer 11 L
The page is shown, but with empty space where the diagram is and it tries loading something forever.
In Firefox and Chrome it works fine.
I have no idea why it "freezes" in IE 11. Will check from other machines to see if this is always happening or not.
The easiest way to handle this is to take advantage of IIS host headers and make the proxied site believe it is responding as www.example.com:80 rather than localhost:8080. It turns out the AAR reverse proxy has an equivalent of Apache's ProxyPerserveHost setting it just isn't very well documented nor exposed in the UI.
To enable this setting you will need to open an elevated shell and run:
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/proxy -preserveHostHeader:true
Then configure the target site to listen at 127.0.0.1:80 with the appropriate host header and then configure the proxy to proxy back to localhost with the request and it should line up.

How to get Dynamic URL with the help of Web.Config and PHP

Suppose i have
3 php pages
www.example.com/page1.php?var1=data1&var2=data2&var3=data3
www.example.com/page2.php?var1=data1&var2=data2&var3=data3
www.example.com/page3.php?var1=data1&var2=data2&var3=data3
For good SEO . I need URL like
www.example.com/page1/data1-data2-data3
www.example.com/page2/data1-data2-data3
www.example.com/page3/data1-data2-data3
i need all the variables for proper functioning of php pages. Some suggests me to use htaccess file but my website is on godaddy windows hosting so htaccess doesn't work ..
.
Go Daddy allows you to use URL rewrite module if you are on windows hosting plan. You can achieve the desired effect with URL routing.
http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module should give you all the information you need for setting up the appropriate rewrite rule.

Trying to map subdomain to another using ISAPI Rewrite on IIS 6

I've been experiementing with URL rewriting in IIS 6 and 7. On IIS 6, I've been using ISAPI Rewrite 3 and am trying to map URLs for one subdomain to another e.g.
http://subdomain1.domain.com/*
would be mapped to:
http://subdomain2.domain.com/*
I've tried to achieve this using:
RewriteEngine on
RewriteCond Host: subdomain1.domain.com
RewriteRule (.*) subdomain2.domain.com/$1
but nothing seems to happen or show up in the IIS log or rewrite.log. I must be missing somethin to enable logging here - any ideas? Also, if anyone could suggest why my rules don't seem to be working it would be much appreciated.
One further question (sorry!) - was wondering on IIS 7 using the rewrite module, I can use the rewrite rules to redirect to content hosted on another instance of IIS (on a different server machine) but can't use the rewrite action to simply mask the URL - is this possible? At the moment, I'm just getting a 403 - forbidden error.
Many thanks for your help.
With regards to your second question about rewriting on IIS 7, you can use the Application Request Routing module to set up a reverse proxy between 2 servers so that content requested from the first server is seamlessly served from the second server.
http://learn.iis.net/page.aspx/489/using-the-application-request-routing-module/

How to implement URL rewrite in classic ASP using custom 404 page?

My web host told me that they are using Windows IIS (not sure about the version) and are unable to implement a URL rewrite for me. I am now looking at alternative ways to do this. Obviously, I don't have access to the IIS server. I read somewhere that using a custom 404 page, I am able to implement a URL rewrite from my end using classic ASP.
I want to do a URL rewrite for subdomain.mydomain.com to www.mydomain.com/subdomain.
I am a bit lost about the steps that must be taken to implement URL rewrite. Can someone take me through the steps?
Thanks
Request.ServerVariables("HTTP_HOST") will give you the subdomain.
if Request.ServerVariables("HTTP_HOST")="subdomain.domain.com" then
response.redirect("http://domain.com/subdomain")
end if
You can get URL Rewriting on IIS6 with IIRF - it's free. If your web host can install it for you., it's easy to get rewrites on IIS. If the web host has IIS7 or later, then they can use the URL Rewriting module that's included in IIS7.

Resources