【问题标题】:Zend Framework 2 IIS url rewriteZend Framework 2 IIS url 重写
【发布时间】:2013-03-16 16:07:42
【问题描述】:

我将我的 zend 项目从 Apache 移动到 IIS 7 并设置了 URL 重写。 主页显示正常,但 css 和 javascript 没有加载。

这是我的重写脚本

<?xml version="1.0" encoding="UTF-8"?>
    <configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <clear />
                <add value="index.php" />
            </files>
        </defaultDocument>
        <rewrite>
            <rules>
                <rule name="Imported Rule 1" stopProcessing="true">
                    <match url="^.*$" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="public/index.php" />
                </rule>
                <rule name="Imported Rule 1-1" stopProcessing="true">
                    <match url="\.(js|ico|txt|gif|jpg|png|css)$" ignoreCase="false" negate="true" />
                    <action type="Rewrite" url="public/index.php" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

这里是原始的 mod_rewrite 规则

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

有什么建议吗?

【问题讨论】:

  • 您对 apache 使用的原始规则是什么?您的所有请求都发送到一个裸露的public/index.php

标签: iis-7 url-rewriting zend-framework2


【解决方案1】:

在梳理了Zend2的文档之后,我找到了这个例子。完美运行!我希望这对其他人有所帮助。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
     <rewrite>
         <rules>
             <rule name="Imported Rule 1" stopProcessing="true">
                 <match url="^.*$" />
                 <conditions logicalGrouping="MatchAny">
                     <add input="{REQUEST_FILENAME}"
                         matchType="IsFile" pattern=""
                         ignoreCase="false" />
                     <add input="{REQUEST_FILENAME}"
                         matchType="IsDirectory"
                         pattern="" ignoreCase="false" />
                 </conditions>
                 <action type="None" />
             </rule>
             <rule name="Imported Rule 2" stopProcessing="true">
                 <match url="^.*$" />
                 <action type="Rewrite" url="index.php" />
             </rule>
         </rules>
     </rewrite>
 </system.webServer>
</configuration>

【讨论】:

  • 我确信它可以组合成一个规则,但如果它以这种方式工作...... :)
  • @aserwin 嗨,你能告诉我你是如何让 ZF2 在 IIS7 上工作的吗?我按照指南添加了 URL 重写,但似乎 URL 重写从未完成。有什么建议吗?
  • 这对我也完全有用,我试图将 .htaccess 文件转换为重写规则,这让我自己死了。谢谢@aserwin !!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-07-19
  • 2010-10-12
  • 2012-09-06
  • 2016-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多