具有web.config文件的IIS上的Codeigniter 2
【腾讯云】亏本大甩卖,服务器4核16G 1年370元(带宽12M,系统盘120GB SSD盘,月流量2000GB)!!!!!!
云产品 配置 价格
服务器 1核2G,带宽5M,系统盘50GB SSD盘,月流量500GB 38元/年
MySQL 1核1G 19元/年
服务器 16核32G,带宽18M,系统盘250GB SSD盘,月流量5000GB 1197元/年
点我进入腾讯云,查看更多详情

I have a codeigniter app working fine locally with WAMP. However, I am having trouble getting it to work on an IIS server. Please note that I do not want to enable query strings.

Here is what I currently have in my web.config file:

    <?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>  

This causes the main page to load properly: www.website.com/policies

However, when I click on an item to go to: www.website.com/policies/policy/view/31

The proper page is not displayed. The main page continues to be displayed.

The controller is Policy and the function is view(). The Codeigniter files are in a policies/ folder on the server.

I think the problem may be with my web.config file. The Config file's $config['base_url'] is dynamically calculated and is the correct one. The Config file's $config['index_page'] is blank. What do you think is causing this problem?

Thank you all for your help.

#0

Have you look at the example in the CI forums?

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>  

#1

i have placed the following web.config code in the root and it worked perfectly.

<?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>

#2

Uff!!! Oh! My God!!!

Recently I had made an admin control panel with CI and grocery crud . It was working great with WAMP on my local server with pretty url and redirection. I was talking about the CI is best framework I had ever work. It’s so easy to use and very well documented Cheers!! to CodeIgniter.

But when I had move my admin panel on IIS server 7.XX then seems my nightmare starts. Everything was stopping No redirection, No error display nothing was happening. I was so scared why it’s happening. I dig Google, stack overflow, CI forum almost 6 hours. I didn't received anything from anywhere. I was so sad :(

I can’t think what I should do. Then, I have made myself cool and calm and start to review everything step by step that is here:

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 main directory (CI working folder) not in root folder

How to convert .htaccess in web.config?

Then, I found that everything is correct except ‘mysqli’ extension was not loaded on IIS Server and my database config credentials was wrong. Then I made changes in php.ini (check’ phpinfo()’ to find php.ini path on IIS Server) line no 881 with uncomment extension=php_mysqli.dll.

Here is my CI config settings:

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

After that, reopen my CI admin panel now!!!!!! Everything wow!! wow!! working like charm :) he he he…. I was so happy :) :)

Here is my web.config file

<?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>

Here is my pretty URL type

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

administrator is my  admin folder

admin is my controller

and showUsers in my controller method

Hope my bad experience will help somebody :)

#3

It turns out I didn't have Rewrite installed. This did the trick:

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

I'm not sure if codeigniter's error page may have masked the error somewhat, because I couldn't determine that it wasn't installed from the browser's error screen. Also Event Viewer, IIS logs, and PHP logs all were not helpful for this situation.

#4

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>

推荐文章

检测RichTextBox中的粘贴

检测RichTextBox中的粘贴

推荐文章

使用安装项目调用x64程序集中的自定义操作

使用安装项目调用x64程序集中的自定义操作

推荐文章

如何批量创建并写入文本文件

如何批量创建并写入文本文件

推荐文章

登录帐户的脚本(JS)不工作

登录帐户的脚本(JS)不工作

推荐文章

有没有更简单的方法可以为C中的方法创建重载?

有没有更简单的方法可以为C中的方法创建重载?

推荐文章

c范围问题

c范围问题

推荐文章

下面的c++代码是做什么的

下面的c++代码是做什么的

推荐文章

数据库设计问题

数据库设计问题

推荐文章

在appEngine中上传文件确实需要

在appEngine中上传文件确实需要

推荐文章

获取克隆对象的动态高度

获取克隆对象的动态高度

推荐文章

如何防止XmlReader跳转到文件结尾,或如何重置读取器

如何防止XmlReader跳转到文件结尾,或如何重置读取器

推荐文章

这个jQuery代码中有什么错误?

这个jQuery代码中有什么错误?

推荐文章

php引用数组

php引用数组

推荐文章

闪光AS3。。。(rest)参数

闪光AS3。。。(rest)参数

推荐文章

Django:避免服务器端和客户端验证代码重复

Django:避免服务器端和客户端验证代码重复

推荐文章

以不占用旧空间的方式使用css3进行缩放

以不占用旧空间的方式使用css3进行缩放