如何使用IIS7 URL重写来隐藏虚拟目录?
我有一台带有 IIS7 的服务器,用于托管多个不同的站点以进行测试。由于官僚主义过多,我无法使用主机标头(我无法在我们的内部 DNS 服务器上获取新条目,并且用户无法更改其本地主机文件)。
我已在 IIS 中设置默认站点,除了包含站点测试版本的虚拟目录外什么都没有
默认站点
<代码>--->测试站点1
<代码>--->测试站点2
因此,当我要求测试用户测试一个站点时,我告诉他们去 http://testserver/testsite1
问题是这些站点在任何地方都使用虚拟路径,所以他们不会'工作正常。例如,网站正在使用 /css/main.css
查找样式表,但找不到它,因为根目录下没有 /css
文件夹默认站点。像这样的事情太多了,需要修复才能改变网站的工作方式。
IIS7 URL 重写对我有帮助吗?如果是这样,我该如何使用正则表达式模式?
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 versions of 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为在这种情况下重写对你没有帮助。
如果您可以更改代码,您可以执行以下操作:添加
到主模板的
标记(如果有的话),这样绝对根 / 将始终解析为正确的虚拟目录。
我还看到人们使用像
get_img('button.jpg')
这样的代码,它将通过服务器端逻辑解析正确的路径。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.URL 重写不会比虚拟路径为您提供更多功能。他们将帮助翻译传入请求以到达正确的应用程序页面,但他们将无法调整该应用程序内的任何内部服务器相对绝对链接以访问正确的 URL。
您可能需要考虑类似反向代理之类的东西,您的测试服务器上有许多虚拟服务器充当底层应用程序代理的应用程序。它可以处理响应并将嵌入的 URL 重写为正确的 URL 路径(例如,按照 Richard 的建议插入
标记或更改实际的 html 链接) 。我相信可能有反向代理可以开箱即用地执行此操作,但我没有任何经验。如果您需要有关此选项的帮助,我建议您转到 Serverfault,因为设置这样的东西更多的是面向服务器而不是与编程相关。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.