IIS重写设置的间歇性更改


IIS Intermittent Change of Rewrite Settings

我的应用程序是基于CodeIgniter构建的,该应用程序运行在Windows Server 2008 R2标准的IIS7.5上。

我们还有4个独立的数据库,每个操作状态中有一个在同一台服务器上运行。(我知道可能不是最佳实践,但这是我被赋予的工作。我不是最初的设计师)。

所以我的文件夹结构是这样的,并且对于每个状态都是重复的。

wwwroot/
  |
  |-{STATE}/
  |----|index.php //CI Index.php
  |-{STATE}/
  |----|index.php //CI Index.php

状态文件夹是以大写字母书写名称的windows目录。

每个文件夹都有一个web.config文件,用于将uri请求重写为index.php

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpErrors errorMode="Detailed" />
        <asp scriptErrorSentToBrowser="true" />
        <rewrite>
        <rules>
            <rule name="RuleRemoveIndex" stopProcessing="true">
                <match url="^(.*)$" ignoreCase="true" />
                <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="index.php?{R:1}" appendQueryString="true" />
            </rule>
        </rules>
        </rewrite>
    </system.webServer>
</configuration>

这就是我困惑的地方。

应用程序有时工作,有时不工作,这取决于状态组件(https://{SUB}。{DOMAIN}:{PORT}/{state}/}URI})是否用大写字母书写。

当我最初把它放在服务器上时,我用小写字母{state}对它进行了测试,一切都很好。第二天我回来了,发现使用小写字母会导致CodeIgniter404错误。但如果我使用大写字母{STATE},它可以找到。然后它会再次改变。

在使用相同的原理进行了一些url重新站点测试之后:http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module但是改为php,我注意到

我还做了一些URL重写测试,看看URL重写的结果是什么,基于这里的aspx版本:http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module但改为php。我发现$_SERVER['SCRIPT_NAME']保留了{STATE}的第一种类型(大写或小写)。我的临时解决方案就是我确信的糟糕做法,我在index.php文件的开头添加了这个脚本

$_script_name = $_SERVER['SCRIPT_NAME'];
$_script_name_array = explode('/', $_script_name);
$_script_name_array[1] = strtolower($_script_name_array[1]);
$_script_name = implode('/', $_script_name_array);
$_SERVER['SCRIPT_NAME']=$_script_name;

它已经解决了一半的问题,它基本上强制使用小写的状态。如果能找到一个解决方案,那么{state}是否用大写字母书写就无关紧要了,那就太好了。

我希望这里有人能有个主意。

IIS重写在这种情况下会很方便

将以下代码添加到位于web文件夹根目录中的web.config文件中。

<rule name="LowerCaseRule" stopProcessing="true">
<match url="[A-Z]" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{URL}}" />
</rule>

在这里URL重写你可以找到更多的细节。希望这对你有帮助。