开发者

Tricking IIS 6.0 html web site into thinking it's at the root

I have no idea how to search for this one and perhaps Serverfault would be better but I'll start here.

I have a HTML web site running at the root of one of my webservers. It runs fine and dandy. I needed to make a test environment for it and where I can't run it in the root of the websever. I have to make a directory on the test server. For instance:

http://myTestserver/HtmlWebsite/index.html instead http://myProdserver/index.html

Once I throw it into the directory, most everything breaks. Some images won't load, javascript files can't be found, mass hysteria!

I discovered that the author of said site had used a mix of absolute and relative directory paths in all the files hence why some images loaded correctly.

I can go in and edit all the files to be relative. But I'm wondering if I can make IIS 6.0 think that the web app directory it is in is the root of the webserver. So if I have an absolute path in the HTML like:

<img src="/_support/loadme.jpg" />

it would give me the image for either http://myTestserver/HtmlWebsite/_support/loadme.jpg or http://myProdserver/_support开发者_如何学Go/loadme.jpg.

Can I get IIS 6.0 to do my bidding or am I stuck editing paths?


Unfortunately you'll either have to fix the absolute URL's across the site or run the site in it's own website in the root.

Is there no way you can get a new site created on the IIS6 test server?


You should be able to by using URL rewriting

First you install ISAPI Rewrite, found here: http://www.helicontech.com/isapi_rewrite/

Then you create a config with the following rule:

RewriteEngine on    
RewriteRule (.+) /HtmlWebsite$1

What it does is it takes your request, say /index.html, and internally rewrites it to /HtmlWebsite/index.html, which is (ironically) tricking you into thinking you're calling from root when in fact it fetches it from the subfolder.

You might have to add or change the rule if you got more stuff on your test server, but that's the gist of it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜