[英]IIS virtual directory root path redirect for PHP
I have a PHP website hosted on IIS 8. 我在IIS 8上托管了一个PHP网站。
The site is hosted on the default site, in a virtual directory. 该站点托管在默认站点的虚拟目录中。
Example: http://192.168.1.1/virtual/index.php 示例: http : //192.168.1.1/virtual/index.php
The web page loads correctly, the problem is with the URLs, CSS and JS. 网页加载正确,问题出在URL,CSS和JS。
<script type="text/javascript" src="/js/jquery/jquery-1.11.0.min.js">/script>
will refer to: 将指:
<script type="text/javascript" src="http://192.168.1.1/js/jquery/jquery-1.11.0.min.js"></script>
This causes 404 errors and the pages don't load correctly - as it is referring to the parent of the virtual directory. 这将导致404错误,并且页面无法正确加载-因为它是指虚拟目录的父目录。 This is a PHP CMS, and I cannot go and modify each and every url.
这是一个PHP CMS,我无法修改每个URL。
I have tried using all sorts of redirects in web.config, with no success. 我尝试在web.config中使用各种重定向,但均未成功。
Please help. 请帮忙。
If i understand you correctly you would want to ensure that all the JS and CSS links still hit the same path but within the virtual directory. 如果我对您的理解正确,那么您将需要确保所有JS和CSS链接仍然位于虚拟目录中,但仍命中相同路径。 I think this rewrite should work, make sure it gets added in the web.config of the root site and not the web.config of virtual directory:
我认为此重写应该起作用,请确保将其添加到根站点的web.config中,而不是添加到虚拟目录的web.config中:
<system.webServer>
<rewrite>
<rules>
<rule name="css_js_to_virtual">
<match url="(.*).(js|css)" />
<action type="Rewrite" url="/virtual/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.