9

我有一个使用 WAMP 在本地运行良好的 codeigniter 应用程序。但是,我无法让它在 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>  

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

然而,当我点击一个项目去:www.website.com/policies/policy/view/31

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

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

我认为问题可能出在我的 web.config 文件上。Config 文件的 $config['base_url'] 是动态计算的,是正确的。配置文件的 $config['index_page'] 是空白的。你认为是什么导致了这个问题?

感谢大家的帮助。

4

5 回答 5

34

你看过 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>  
于 2011-03-23T18:21:23.413 回答
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>
于 2014-11-03T07:38:40.050 回答
3

原来我没有安装 Rewrite。这成功了:

http://www.iis.net/downloads/microsoft/url-rewrite

我不确定 codeigniter 的错误页面是否在某种程度上掩盖了错误,因为我无法确定它不是从浏览器的错误屏幕安装的。此外,事件查看器、IIS 日志和 PHP 日志都对这种情况没有帮助。

于 2012-09-24T22:41:38.077 回答
3

好的!

最近我用 CI 和杂货杂货做了一个管理控制面板。它在我的本地服务器上与 WAMP 配合得很好,具有漂亮的 URL 和重定向。我在谈论 CI 是我工作过的最好的框架。它非常易于使用,并且有很好的文档记录 干杯!到 CodeIgniter。

但是当我不得不在 IIS 服务器 7.XX 上移动我的管理面板时,我的噩梦似乎开始了。一切都停止了没有重定向,没有错误显示什么都没有发生。我很害怕为什么会这样。我在谷歌、堆栈溢出、CI 论坛上挖了将近 6 个小时。我没有从任何地方收到任何东西。我很伤心:(

我想不出我应该做什么。然后,我让自己冷静下来,开始一步一步地回顾这里的一切:

1.    Set error reporting on
2.    Check PHP info
3.    Check redirect/rewrite
4.    Check MySQL/MySQLi extension loaded or not in IIS server
5.    Converted my .htaccess file rule with web.config rule (Really helped me)
6.    Put web.config file in the main directory (CI working folder) not in the root folder

如何在 web.config 中转换 .htaccess?

然后,我发现一切都是正确的,除了 IIS 服务器上没有加载“mysqli”扩展名并且我的数据库配置凭据错误。然后我在 php.ini 中进行了更改(检查'phpinfo()'以在 IIS 服务器上找到 php.ini 路径)第 881 行,取消注释扩展 = php_mysqli.dll。

这是我的 CI 配置设置:

$config['base_url']    = '';
$config['index_page'] = '';
$config['uri_protocol']    = 'REQUEST_URI';

之后,现在重新打开我的 CI 管理面板!!!!!!一切哇!哇!!像魅力一样工作:) 嘿嘿嘿…… 我非常开心 :) :)

这是我的 web.config 文件

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Imported Rule 1">
                    <match url="(.*)" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{HTTPS}" pattern="off" ignoreCase="false" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}{URL}" redirectType="Found" />
                </rule>
                <rule name="Imported Rule 1-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}" appendQueryString="false" />
                </rule>
                <rule name="Imported Rule 2" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{URL}" pattern="^application.*" ignoreCase="false" />
                    </conditions>
                    <action type="Rewrite" url="/index.php?/{R:1}" appendQueryString="false" />
                </rule>
                <rule name="Imported Rule 3" 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" />
                    </conditions>
                    <action type="Rewrite" url="index.php?/{R:1}" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

这是我漂亮的 URL 类型

https://mysite.abc.com/administrator/admin/showUsers

the administrator is my  admin folder

admin is my controller

and showUsers in my controller method

希望我的糟糕经历会对某人有所帮助:)

于 2013-03-05T15:53:04.723 回答
1
You can like this,
<?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="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
              <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />
          </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
于 2016-10-26T07:42:19.043 回答