2011-03-23 62 views
5

我有一个codeigniter应用程序,可以在WAMP本地工作。但是,我无法使其在IIS服务器上运行。请注意,我不想启用查询字符串。IIS上的Codeigniter 2和web.config文件

这是我目前在我的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 ['base_url']是动态计算的,并且是正确的。配置文件的$ config ['index_page']为空。你认为是什么造成这个问题?

谢谢大家的帮助。

+0

做完在服务器上,它看起来像URL重写器已设置。这里是它的信息: _SERVER [“IIS_UrlRewriteModule”] \t 7.1.0761.0 – stevetronix 2011-03-23 18:27:38

回答

28

你看看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> 
+3

谢谢Jakub。我只是想分享我的问题的解决方案。在config.php文件中,$ config ['uri_protocol']被设置为'QUERY_STRING'。我将它改为$ config ['uri_protocol'] ='AUTO'。然后,我改变了的web.config规则: <规则名称= “MyRule的”> <匹配URL = “(。*)^ $”/> <添加输入= “{} REQUEST_FILENAME” 使用MatchType = “IsFile”negate =“true”/> stevetronix 2011-03-24 22:06:36

+1

@stevetronix谢谢你做到了。你节省了我的10分钟。 – 2013-09-12 13:32:02

+2

事实上,否定匹配模式将提供匹配请求中的任何地方的字符串,你可能不需要。对于带有这些扩展名的静态文件,正确的正则表达式是:'pattern =“^。+ \。(css | js | jpg | jpeg | png | gif | ico | htm | html | eot | woff | ttf | svg | txt)$ “negate =”true“' – Ade 2013-10-15 14:20:20

2

原来我没有安装重写。这奏效了:

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

我不知道,如果CodeIgniter的错误页面可能有所掩盖错误,因为我不能确定它是不是从浏览器的错误屏幕安装。此外事件查看器,IIS日志和PHP日志都对这种情况没有帮助。

2

Uff !!!哦!天哪!!!

最近我做了一个管理控制面板与CI和杂货零碎。它在我的本地服务器上使用WAMP工作得很好,具有漂亮的URL和重定向。我在谈论CI是我曾经工作过的最好的框架。这是非常容易使用和非常有据可查的干杯!到CodeIgniter。

但是当我将IIS管理面板移动到IIS服务器7.XX上时,似乎我的噩梦开始了。一切都停止没有重定向,没有错误显示没有任何事情发生。我很害怕它为什么会发生。我挖Google,堆栈溢出,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 main directory (CI working folder) not in root folder 

How to convert .htaccess in web.config?

然后,我发现除mysqli扩展名未在IIS服务器上加载并且我的数据库配置凭据错误之外,所有内容都是正确的。然后我在php.ini中进行了更改(检查'phpinfo()'以查找php.ini IIS服务器上的路径)line no 881 with uncomment extension = 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> 

这里是我的漂亮的网址类别

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

administrator is my admin folder 

admin is my controller 

and showUsers in my controller method 

希望我不好的经验将帮助别人:)

2

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

非常感谢!它对我来说非常合适。 – Rahmuna 2015-09-13 06:14:03

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>