如何在Windows Server和IIS上移除CodeIgniter中的index.php?

10

如何在Windows Server和IIS上删除Codeigniter中的index.php?

当我搜索答案时,我找到了以下内容:

如何在Windows Azure上重写Codeigniter的index.php

但是当我尝试后发现我的CI仍然需要index.php才能运行。在我编辑web.config之前,该文件必须添加到哪里?还有其他步骤吗?

4个回答

19

如果未安装URL Rewrite模块,请从此处安装:http://www.iis.net/downloads/microsoft/url-rewrite

请检查完整的web.config文件。将其放置在与index.php相同的文件夹中。

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

它在 Windows server 2008 R2 中的 IIS 中工作。


1
将web.config放在根目录中。 用户代码:

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


谢谢,它对我有用,我的Codeigniter项目已经部署在共享的Windows托管上。我在根目录中创建了一个web.config文件并添加了这段代码。 - ramya

1

这个答案比其他答案更加安全(多疑),是基于CakePHP的方式实现的。假设您有一个名为“public”的目录,其中包含所有js、css、图像和字体文件。如果您想要允许其他扩展名,请将它们添加到第二条规则中。您可以通过替换规则1和2中的“public”一词来更改目录名称。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Exclude direct access to public/*" stopProcessing="true">
                    <match url="^public/(.*)$" ignoreCase="false" />
                    <action type="None" />
                </rule>
                <rule name="Rewrite routed access to assets by extension" stopProcessing="true">
                    <match url="^(.*)(\.(css|js|otf|eot|svg|ttf|woff|woff2|jpg|png|gif|ico))$" />
                    <action type="Rewrite" url="public/{R:1}{R:2}" appendQueryString="false" />
                </rule>
                <rule name="Rewrite requested file/folder to index.php" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <action type="Rewrite" url="index.php" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

0
你应该将web.config文件与你的项目一起上传并编写代码。

web.config

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

    <directoryBrowse enabled="false" />

      <rewrite>
        <rules>
          <rule name="Hide Yii Index" 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" appendQueryString="true" />
          </rule> 
        </rules>
      </rewrite>
  </system.webServer>
</configuration>

如果您仍然遇到问题,请查看以下链接:

PHP MVC框架IIS index.php解决方案


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接