使用web.config文件在IIS上的Codeigniter 2

ste*_*nix 8 php iis codeigniter web-config codeigniter-2

我有一个codeigniter应用程序在WAMP本地工作正常.但是,我无法让它在IIS服务器上工作.请注意,我不想启用查询字符串.

这是我目前在web.config文件中的内容:

    <?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Clean URL" stopProcessing="true">
                    <match url="^(.*)$" />
                    <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="false" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>  
Run Code Online (Sandbox Code Playgroud)

这会导致主页面正确加载:www.website.com/policies

但是,当我点击某个项目时,请访问:www.website.com/policies/policy/view/31

不显示正确的页面.主页面继续显示.

控制器是Policy,函数是view().Codeigniter文件位于服务器上的策略/文件夹中.

我认为问题可能出在我的web.config文件中.Config文件的$ config ['base_url']是动态计算的,是正确的.Config文件的$ config ['index_page']为空白.您认为导致此问题的是什么?

感谢大家的帮助.

Jak*_*kub 32

您是否看过CI论坛中的示例?

http://codeigniter.com/forums/viewthread/91954

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Rewrite to index.php">
                    <match url="index.php|robots.txt|images|test.php" />
                    <action type="None" />
                </rule>
                <rule name="Rewrite CI Index">
                    <match url=".*" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php/{R:0}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>  
Run Code Online (Sandbox Code Playgroud)

  • 谢谢Jakub.我只是想分享我的问题的解决方案.在config.php文件中,$ config ['uri_protocol']设置为'QUERY_STRING'.我将其更改为$ config ['uri_protocol'] ='自动'.然后,我将web.config规则更改为:<rule name ="MyRule"> <match url ="^(.*)$"/> <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 ="false"/> </ rule> (3认同)
  • @stevetronix谢谢你做了神奇的事.你节省了我的10ks分钟. (2认同)
  • 实际上,提供的否定匹配模式将匹配请求中的任何位置,您可能不需要.具有这些扩展名的静态文件的正确正则表达式是:`pattern ="^.+ \.(css | js | jpg | jpeg | png | gif | ico | htm | html | eot | woff | ttf | svg | txt)$ "否定="真"" (2认同)

小智 5

我已将以下 web.config 代码放置在根目录中,并且运行良好。

<?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="Imported Rule 1" stopProcessing="true">
                        <match url="^(.*)$" ignoreCase="false" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{URL}" pattern="^system.*" ignoreCase="false" />
                        </conditions>
                        <action type="Rewrite" url="/index.php?{R:1}" />
                    </rule>
                    <rule name="Imported Rule 2" stopProcessing="true">
                        <match url="^(.*)$" ignoreCase="false" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                            <add input="{R:1}" pattern="^(index\.php|images|robots\.txt|css)" ignoreCase="false" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="index.php?{R:1}" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>
Run Code Online (Sandbox Code Playgroud)