views:

576

answers:

2

I have a server with IIS7 that I am using to host several different sites for testing. Due to an overabundance of bureaucracy, I am unable to use host headers (I can't get new entries on our internal DNS server and users can not change their local hosts file).

I have set up the default site in IIS to have nothing but virtual directories that have test version on my sites

Default Site
---> TestSite1
---> TestSite2

So when I ask the test user to test a site I tell them to go to http://testserver/testsite1

The problem is that the sites use virtual paths everywhere so they don't work right. For example, the site is looking for the style sheet using /css/main.css but it won't find it because there is no /css folder on the root of the default site. There are far too many things like this to fix to change how the site works.

Will IIS7 URL rewriting help me here? If so, what do I use for the regex pattern?

A: 

I don't think rewriting will help you in this situation.

If you can change the code you can do something like add

<base href="http://testserver/testsite1/" /> to the <head> tag of your master template (if you have one) so the absolute root / will always resolve to the correct virtual directory.

I've also seen people use code like get_img('button.jpg') which will resolve the correct path through server side logic.

Ryu
Unfortunately, altering the code is not practical. It looks like I will need to lean on our network guys to get the DNS entries so I can use host headers. I will consider this option for future projects though. Thanks.
Loki Stormbringer
A: 

URL rewriting will do no more than what virtual paths will provide you. They will help translate an incoming request to get to the right application page, but they will not be able to adjust any internal server-relative absolute links within that application to hit the right URLs.

You may want to consider something like a reverse proxy where you have your test server with it's many virtual applications acting as a proxy for the underlying applications. It can process the responses and re-write the embedded URLs to the right URL paths (e.g. by inserting a <base href=''> tag as Richard suggests or by changing the actual html links). I believe there may be reverse proxies out there that do this out of the box, but I don't have any experience with it. If you want help with this option, I'd suggest wandering over to Serverfault since setting such a thing up is more server orientated than programming related.

iammichael