【问题标题】:Codeigniter URL rewrite in Web.config not working in sub directory on Windows IIS serverWeb.config 中的 Codeigniter URL 重写在 Windows IIS 服务器的子目录中不起作用
【发布时间】:2013-12-19 06:40:12
【问题描述】:

我使用 PHP 框架 - Codeigniter 2 开发了我的网站。这个网站有一个前端和一个后端。

对于后端,我在网站的根目录中创建了一个名为 webadmin 的目录。

本网站之前使用 APACHE 服务器托管在 LINUX 操作系统上,但最近我们已经转移到使用 IIS 服务器的专用 WINDOWS 操作系统服务器上。

以前在 LINUX 上,我使用 2 个 htaccess 文件,一个在根目录,另一个在我的子目录。它在这两种情况下都运行良好。

现在由于 IIS 服务器,我必须将所有设置导入 IIS Web.config 文件。使用 index.php 的重写规则生成的 web.config 非常适合我的前端,但在我的子目录 http://www.somedomain.com/webadmin 中不起作用。

我在我的根目录中使用了以下 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="true" />
            </rule>
        </rules>
    </rewrite>
        <defaultDocument>
            <files>
                <clear />
                <add value="Index.php" />
                <add value="Index.html" />
                <add value="Index.htm" />
                <add value="Index.cfm" />
                <add value="Index.shtml" />
                <add value="Index.shtm" />
                <add value="Index.stm" />
                <add value="Index.php3" />
                <add value="Index.asp" />
                <add value="Index.aspx" />
                <add value="Default.htm" />
                <add value="Default.asp" />
                <add value="Default.aspx" />
            </files>
        </defaultDocument>
        <httpErrors errorMode="Detailed" />
    </system.webServer>
</configuration>

接下来是我的子目录中的 web.config 文件,它不起作用并给我 404 错误。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <security>
            <requestFiltering allowDoubleEscaping="true" />
        </security>
        <rewrite>
            <rules>
                <rule name="YOURLS" stopProcessing="true">
                    <match url="^webadmin/(.*)$" ignoreCase="false" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/webadmin/index.php/{R:1}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

【问题讨论】:

  • 拥有一个或多个 web.config 文件也是一种好习惯。 ???

标签: php .htaccess codeigniter iis web-config


【解决方案1】:

这是我使用的适合我的版本。只需将 SUBDOMAIN 替换为您的。记得在配置中也将 base_url 更改为带有子域的那个。

    <?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|ttf|woff" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php/SUBDOMAIN/{R:0}" />
                </rule>
            </rules>
        </rewrite>
     </system.webServer>
</configuration> 

【讨论】:

    猜你喜欢
    • 2012-08-05
    • 1970-01-01
    • 2017-02-21
    • 1970-01-01
    • 2015-12-08
    • 2023-03-08
    • 2015-07-10
    • 1970-01-01
    • 2017-08-23
    相关资源
    最近更新 更多