Routing a url to fetch content from another site - windows

Environment: IIS 7.
I have a default site www.domain.com. Folder C:Inetpub/wwwroot/domain
There is subdomain www.subdomain.domain.com. Folder C:Inetpub/wwwroot/domain/subdomain.
Now, I have set up a new website at an external server, say www.newdomain.com. I cannot host www.newdomain.com on the same IIS server (as mentioned above) due to some constraints.
In this setup, how do I get www.subdomain.domain.com/blog to show all the content available on www.newdomain.com while preserving the URL as www.subdomain.domain.com/blog
How could this be achieved in IIS 7?

You would have to put the entire www.subdomain.domain.com on the other server. You can't put just the /blog path somewhere else.
How would any client know to go to that other server for /blog if the DNS for the subdomain points to the first server?
Alternatively, you could create blog.subdomain.domain.com for the blog server.

Possible approaches:
Host the new website as blog.domain.com with the actual content hosted on a different server (not the same IIS server as domain.com)
Set-up a ProxyPass on subdomain.domain.com/blog to the new website. I know how do to this on Apache (via mod_proxy and ProxyPass), but not sure how to do this with IIS. Probably ARR can help you.

I was finally able to do this by reverse proxy rewrite rule. For those who have similar trouble here is the solution:
Go to the site node hosting www.subdomain.domain.com and click rewrite rule. If ARR is not installed the IIS Manager will ask you to install it. After installing ARR close and reopen the IIS Manager.
Open the rewrite rule window. There will be a dialog asking to allow reverse proxy to servers outside your server farm, accept that. In the Inbound rule enter www.newdomain.com. In the from input of the Outbound rule enter www.newdomain.com and in the to input enter www.subdomain.domain.com. click apply changes.
This will route the entire www.subdomain.domain.com to newdomain.com. What you need is to route only the /blog link.
To do this go to rewrite rules and select the rewrite rule you just created. Click edit and in the match section in url input change (.asterix) to ^blog(.asterix). This will apply the rule to route only the /blog.
That all. test your routing in the browser, if everythings fine this should work.

Related

Openlitespeed 301 Moved Permanently problem

I have a new Openlitespeed server on Ubuntu, I have 2 domains pointing to the same IP,
I tried to make a multidomain server so that www.domain1.com would point to one website and www.domain2.com to another.
I followed this tutorial.
Now when I go to domain1.com:80 it returns "CERR_CONNECTION_TIMED_OUT" and if I look at the network tab it shows:
and redirects me to http://domain1.com:8080/
If I go to domain2.com:80 it's the same but it redirects me to 8088.
Before that, I was hosting two testing pages on 8080 and 8088, but I changed all the settings and can't find what is causing the redirections... (both websites are wordpress)
I managed to resolve this, something inside WordPress was redirecting.
I re-downloaded new WordPress and now it works.

How do I debug an https loaded page using weinre?

I'm trying to debug using weinre, and have set up a simple test in Chrome to make sure everything is working. However, in the developer tools I get the error:
"The page at 'https://myhost/...' was loaded over HTTPS, but ran insecure content from 'http://localhost:8080/target/target-script-min.js': this content should also be loaded over HTTPS.
I had seen some other answers with regards to debugging "Cordova" or "Phonegap". I am not using either of these things and the answers suggested do not seem to apply here. I am trying to debug simple HTML/Javascript only.
I don't see any mention on the weinre web page of enabling https support (it explicitly mentions that it doesn't use https), and I don't have a lot of control over the browser side (this needs to work on various android browsers which are notorious, in my mind anyway, at being totally unfriendly towards local debugging, which is in fact the reason I am trying to debug using weinre), so I am at a loss as to how to proceed. Not using https is out of the question, as the page passes sensitive information; using weinre over http is acceptable because I am tunnelling the connection over ssh.
Update: I have also tried using the boomarklet method: I added the bookmarklet URL to Chrome Mobile, but when I try navigating to the bookmarklet, it appears to unload the original page: I can see the connection made, but when I look at the resources, all I see is what appears to be the bookmarklet. But if I try to run the bookmarklet by typing the name of the bookmarklet until the starred javascript code appears in autocomplete, it stays on the current page, but no targets show up in the client page. I assume it is for the same reason, as I see the bookmarklet referencing http://localhost:2000.
To get by browser restrictions, weinre pages can be served from https instead of http using a reverse proxy. This is somewhat of a brute-force solution, but adding the following lines to the end of my /etc/httpd.conf file were sufficient to proxy all the pages weinre requests from the server: in my case, none of these conflict with existing files or directories.
ProxyPass /target/ http://localhost:8080/target/
ProxyPassReverse /target/ http://localhost:8080/target/
ProxyPass /client/ http://localhost:8080/client/
ProxyPassReverse /client/ http://localhost:8080/client/
ProxyPass /weinre/ http://localhost:8080/weinre/
ProxyPassReverse /weinre/ http://localhost:8080/weinre/
ProxyPass /interfaces/ http://localhost:8080/interfaces/
ProxyPassReverse /interfaces/ http://localhost:8080/interfaces/
ProxyPass /modjewel.js http://localhost:8080/modjewel.js
ProxyPass /images/ http://localhost:8080/images/
ProxyPassReverse /images/ http://localhost:8080/images/
ProxyPass /ws/ http://localhost:8080/ws/
ProxyPassReverse /ws/ http://localhost:8080/ws/
It is also necessary to define window.WeinreServerURL, as Weinre does a regex on http:/ to try to get the URL of the server. This will fail since the server is https, not http. In my case, I added a statement of the following form to the bookmarklet as the first statement in the function:
window.WeinreServerURL="https://server:port/
With this in place I was able to point my browser at https://server:port/client/#anonymous to bring up the debug page, and run the bookmarklet from the page under debug.
Great question and answer, #Michael! I had the same question, and followed your guidance to get things working with my setup, which is with IIS on Windows. I'm posting this here as a reference in case others run into the same issue.
With IIS, I used the following process to setup the reverse proxy:
First off, install the Application Request Routing extension for IIS, along with its dependencies. This makes it super-easy to setup a reverse proxy.
I created a new website for this, to avoid potential conflicts with my existing site. In IIS Manager, right click on Sites and choose Add Web Site.... Give it a name (e.g. 'weinre') and point it at a temporary directory. Change the binding to https, and choose an unused port, such as 8005. You can also add an http binding if you'd like.
Select the newly created site, then double click on the URL Rewrite module.
Click Add Rule(s)... in the right panel, then use the Reverse Proxy template.
Ensure the Enable SSL Offloading box is checked, and then enter the server name/port where the weinre server is located (e.g. `127.0.0.1:8080'). Add the rule, restart the website, and you're done!
Now, to use it, simply update the paths to the target script to point to the port you bound in step 2. And, as Michael points out, you'll also need to set window.WeinreServerURL as it can't auto-detect with this setup.
Happy Debugging!
You can run weinre on a PaaS like Heroku or Bluemix, which typically provide https termination, so the apps basically get https support for free.
You can try the https version of my public access weinre server, here: https://weinre.mybluemix.net/

Redirect root URL - IIS 7

I have some forums installed on my site at http://ironnoob.com/forums.
My website lives in c:\IronNoob and my forums are installed in c:\IronNoob\forums
I want both "ironnoob.com" and "www.ironnoob.com" to do a server-side redirect to "ironnoob.com\forums".
I'm using IIS 7 and I'm new to setting up this stuff so I don't even know what to google for. I know I can do a client-side redirect with HTML, but I understand that the server-side redirect is nicer. I've figured out how to install the HttpRedirect module for IIS, but if I set up a redirect in the root folder of my site to my forums folder, I get a circular redirect error when visiting ironnoob.com.
HTTP Redirect Settings:
root directory selected in Connections pane of ISS
Check "Redirect requests to this destination"
destination = http://somesite.com/forums
Check "redirect all requests to the exact location"
Check "only redirect requests to content in this directory (not subdirectories)"
Status code: Permanent (301)
Why is it redirecting subdirectories when I told it not to? What is the right way to do this?
Instead of using the HTTP redirect module, you can use the URL rewrite one.
Run the inetmgr command and select your website root. Open the URL rewrite configuration:
Click on Add a rule on the right panel. Select a Blank rule in inbound rules:
From here you have to name your rule and select the Does not match the pattern option. You then have to set the Pattern (in this case, it means that a URL not starting with forums will trigger this rule):
The last step is to set up your redirect. You probably want to go with a 301 redirect as advised by Google:
Click Apply on the right panel and you should be good to go.
NOTE: If your Redirect URL doesn't match your Pattern you will be stuck in an infinite loop (you can test it by simply clicking the Test button will writing your Pattern).
Documentation for this module available here

IIS 7.5 URL Rewrite Different Domains pointed to a single site

I have a single site at www.domain1.com. It's a PHP site being hosted on a Windows 2008/IIS 7.5 box. I need to set up www.domain2.com so that users are redirected to www.domain1.com/subfolder. To the user, they still see www.domain2.com in the address bar but are looking at the www.domain1.com/subfolder.
Any help on how to achieve this would be greatly appreciated!
You need to use IIS Application Request Routing and Url Rewrite modules. This walkthrough describes almost exactly what you are trying to achieve.

Hot to block access to page with defined URL in ASP.NET site on IIS except from one defined IP?

We have ASP.NET web site hosted on IIS.
We need to block access to page "http://www.example.com/sample/page1.aspx" from any IP.
We want to define single IP which can access this page.
What option of IIS or Windows can help me?
If you are using IIS7 + you could use the URL Rewrite Module http://www.iis.net/download/urlrewrite
However if you are using IIS6 you can try a tool like Helicon ISAPI Rewrite http://www.helicontech.com/isapi_rewrite/ which will allow you to write an IP based rule.
Try this in your code behind (although this is not IIS or Windows as you request):
if (Request.UserHostAddress == "1.1.1.1") { }
Obviously substitute the IP address you want!

Resources