aserwin
aserwin

Reputation: 1050

Zend Framework 2 IIS url rewrite

I moved my zend project from Apache to IIS 7 and set up URL Rewrite. The home page shows just fine, but the css and javascript aren't loading.

Here is my rewrite scripts

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

Here are the original mod_rewrite rules

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]

Any suggestions?

Upvotes: 2

Views: 2144

Answers (1)

aserwin
aserwin

Reputation: 1050

After combing through Zend2 documentation, I found this example. Works perfectly! I hope this helps someone else out.

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

Upvotes: 5

Related Questions