【问题标题】:Remove index.php of Codeigniter on IIS?删除 IIS 上 Codeigniter 的 index.php?
【发布时间】:2012-09-30 06:12:09
【问题描述】:

我知道我可以使用以下 web.config 代码删除 url 的“index.php”部分:

<rewrite>
  <rules>
    <rule name="Rule" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="false" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
        <add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" />
      </conditions>
      <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
    </rule>
  </rules>
</rewrite>

问题是我在子目录 (mydomain.com/codeigniter) 中安装了 CI,但我无法理解 web.config 文件。

您知道如何更改它以使其适用于子目录吗?

【问题讨论】:

  • 您是否尝试将子文件夹添加到重写 url 路径? &lt;action type="Rewrite" url="mysubfolder/index.php/{R:1}" appendQueryString="true" /&gt;
  • 谢谢!这有效,但前提是我的第一条规则不存在。我实际上需要两个,一个用于顶级目录,一个用于子目录。

标签: windows codeigniter iis url-rewriting


【解决方案1】:

我在根目录中有 WordPress,在子目录中有我的 CodeIgniter 应用程序。我创建了一个与您类似的web.config 并将其保存在子目录中。我的 CI 应用不再需要 url 中的 index.php。

首先,我在&lt;action url="myapp/index.php/{R:1}"...&gt; 中添加了我的子目录,并希望它可以被限制为仅查看子目录但失败了。我删除了子目录并将其保留为原始但将 web.config 移动到子目录并且它可以工作。

因此,我想也许你可以创建两个具有不同规则的 web.config 文件并将它们保存在不同的目录中。

另一个注意事项可能会有所帮助:启用错误消息以从 IIS 输出详细信息。我使用这些技巧来找出 IIS 如何查找我的文件。分别是&lt;httpErrors errorMode="Detailed" /&gt;&lt;asp scriptErrorSentToBrowser="true"/&gt;&lt;system.web&gt;部分如下:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <system.webServer>

        <httpErrors errorMode="Detailed" />
        <asp scriptErrorSentToBrowser="true"/>

        <rewrite>
        <rules>
            <rule name="RuleRemoveIndex" stopProcessing="true">
                <match url="^(.*)$" ignoreCase="false" />
                <conditions>
                    <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="true"/>
            </rule>
        </rules>
        </rewrite>

    </system.webServer>

    <system.web>
        <customErrors mode="Off"/>
        <compilation debug="true"/>
    </system.web>

</configuration>

【讨论】:

    【解决方案2】:

    把web.config放到根目录下。

    用户代码:

     <?xml version="1.0" encoding="UTF-8"?>
      <configuration>
     <system.webServer>
    
        <httpErrors errorMode="Detailed" />
        <asp scriptErrorSentToBrowser="true"/>
    
        <rewrite>
        <rules>
            <rule name="RuleRemoveIndex" stopProcessing="true">
                <match url="^(.*)$" ignoreCase="false" />
                <conditions>
                    <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="true"/>
            </rule>
        </rules>
        </rewrite>
    
    </system.webServer>
    
    <system.web>
        <customErrors mode="Off"/>
        <compilation debug="true"/>
    </system.web>
    

    【讨论】:

      猜你喜欢
      • 2016-07-05
      • 2016-05-17
      • 1970-01-01
      • 1970-01-01
      • 2011-07-09
      • 1970-01-01
      • 1970-01-01
      • 2012-10-30
      • 2011-10-28
      相关资源
      最近更新 更多