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

时间:2022-09-19 20:23:53

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.

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

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

这是我目前在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>  

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

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

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

但是,当我点击某个项目时,请访问: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.

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

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?

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

Thank you all for your help.

感谢大家的帮助。

5 个解决方案

#1


30  

Have you look at the example in the CI forums?

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

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

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>  

#2


3  

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

我已经在根中放置了以下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>

#3


2  

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

事实证明我没有安装Rewrite。这样就可以了:

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

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.

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

#4


2  

Uff!!! Oh! My God!!!

UFF!哦!天哪!!!

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.

最近我制作了一个带有CI和杂货的管理控制面板。它在我的本地服务器上使用WAMP和漂亮的URL和重定向工作得很好。我在谈论CI是我曾经工作过的最好的框架。它很容易使用,并且有很好的记录!到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 :(

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

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?

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

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.

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

Here is my CI config settings:

这是我的CI配置设置:

$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 :) :)

之后,立即重新打开我的CI管理面板!!!!!!一切哇!!哇!!像魅力一样工作:)他,他......我很高兴 :) :)

Here is my web.config file

这是我的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>

Here is my pretty URL type

这是我漂亮的URL类型

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 :)

希望我糟糕的经历会帮助别人:)

#5


0  

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>

#1


30  

Have you look at the example in the CI forums?

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

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

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>  

#2


3  

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

我已经在根中放置了以下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>

#3


2  

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

事实证明我没有安装Rewrite。这样就可以了:

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

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.

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

#4


2  

Uff!!! Oh! My God!!!

UFF!哦!天哪!!!

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.

最近我制作了一个带有CI和杂货的管理控制面板。它在我的本地服务器上使用WAMP和漂亮的URL和重定向工作得很好。我在谈论CI是我曾经工作过的最好的框架。它很容易使用,并且有很好的记录!到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 :(

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

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?

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

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.

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

Here is my CI config settings:

这是我的CI配置设置:

$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 :) :)

之后,立即重新打开我的CI管理面板!!!!!!一切哇!!哇!!像魅力一样工作:)他,他......我很高兴 :) :)

Here is my web.config file

这是我的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>

Here is my pretty URL type

这是我漂亮的URL类型

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 :)

希望我糟糕的经历会帮助别人:)

#5


0  

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>