【问题标题】:we.config and cakephp applicationswe.config 和 cakephp 应用程序
【发布时间】:2011-07-22 20:50:01
【问题描述】:

有没有办法在 iis 上使用 web.config 来替换 cakephp 应用程序的 .htaccess?

当前的 .htaccess 文件

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
 </IfModule>

更新:

在 IIS6 中使用了导入。它给了我这个 web.config,但站点不起作用。我得到一个白屏。也试过这个http://book.cakephp.org/revisions/view/19937/URL-Rewrites-on-IIS7-Windows-hosts,也没用。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Imported Rule 1" stopProcessing="true">
                    <match url="^$" ignoreCase="false" />
                    <action type="Rewrite" url="webroot/" />
                </rule>
                <rule name="Imported Rule 2" stopProcessing="true">
                    <match url="(.*)" ignoreCase="false" />
                    <action type="Rewrite" url="webroot/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

【问题讨论】:

    标签: php iis cakephp


    【解决方案1】:

    为 IIS 安装 Microsoft URL 重写模块。它会让你导入你的 apache 重写规则。您可以在此处找到该模块:

    http://www.iis.net/download/urlrewrite

    我在 IIS 7.0 和 7.5 上将它与 CakePHP 一起使用,效果很好。

    编辑

    你能帮我试试这个配置吗?

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <clear />
                    <rule name="Imported Rule 1-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="/webroot/index.php?url={R:1}" appendQueryString="true" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>
    

    【讨论】:

    • 谢谢,虽然我听说 IIS 7 内置了 URL 重写功能,它可以使用 web.config 文件。你听说过吗?
    • 我不相信它是作为标准安装的,但是如果没有安装,您可以使用 Web 平台安装程序或通过我给您的链接下载它。安装后,您可以通过双击 IIS 管理器的 IIS 部分中的“URL Rewrite”图标来开始添加规则。您在此处输入的规则存储在 web.config 文件中。
    • 这对您有帮助吗?我可以再帮忙吗?
    • @madphp 我能帮上忙吗?
    • @madphp 我已经更新了我的答案,让我知道它是怎么回事。干杯
    猜你喜欢
    • 1970-01-01
    • 2014-11-04
    • 2012-03-22
    • 1970-01-01
    • 1970-01-01
    • 2014-01-31
    • 2010-12-20
    • 2016-03-06
    • 2011-05-29
    相关资源
    最近更新 更多