2

i'm trying to import .htaccess file into the URL rewrite rule in IIS 7.

the current file in Symfony 2 fails importing it into IIS. i need the help of someone that knows the syntax to translate the file into something usable by IIS, appealing to the fact this work would help any future user of Symfony 2 in IIS.

i apologize for not know the syntax in IIS. and i append the original file /web/.htaccess , excluding all the comments for convenience.

Thanks in advance

DirectoryIndex app.php

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$

    RewriteRule ^(.*) - [E=BASE:%1]
    RewriteCond %{ENV:REDIRECT_STATUS} ^$

    RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
    RewriteCond %{REQUEST_FILENAME} -f

    RewriteRule .? - [L]
    RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /app.php/
    </IfModule>
</IfModule>

the current error output is this:

<rewrite>
  <rules>
    <!--The rule cannot be converted into an equivalent IIS format because of unsupported flags: E-->
    <!--This rule was not converted because it contains references that are not supported: 'ENV::BASE'-->
    <rule name="Imported Rule 3" stopProcessing="true">
      <match url=".?" ignoreCase="false" />
      <conditions>
        <!--# If the requested filename exists, simply serve it.-->
        <!--# We only want to let Apache serve files and not directories.-->
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
      </conditions>
      <action type="None" />
    </rule>
    <!--This rule was not converted because it contains references that are not supported: 'ENV::BASE'-->
  </rules>
</rewrite>

Thanks in advance

Rafael
  • 3,081
  • 6
  • 32
  • 53

2 Answers2

3

If you run the app.php from the root of the domain (http://domain.tld/app.php) than you can remove the ENV:BASE variables. This would result in the following XML to import in IIS:

<rewrite>
  <rules>
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url="^app\.php(/(.*)|$)" ignoreCase="false" />
      <action type="Redirect" redirectType="Permanent" url="/{R:2}" />
    </rule>
    <rule name="Imported Rule 2" stopProcessing="true">
      <match url=".?" ignoreCase="false" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
      </conditions>
      <action type="None" />
    </rule>
    <rule name="Imported Rule 3" stopProcessing="true">
      <match url=".?" ignoreCase="false" />
      <action type="Rewrite" url="/app.php" />
    </rule>
  </rules>
</rewrite>

Edit: from a subdirectory this should work I believe (subdir being "foo"):

<rewrite>
  <rules>
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url="^app\.php(/(.*)|$)" ignoreCase="false" />
      <action type="Redirect" redirectType="Permanent" url="foo/{R:2}" />
    </rule>
    <rule name="Imported Rule 2" stopProcessing="true">
      <match url=".?" ignoreCase="false" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
      </conditions>
      <action type="None" />
    </rule>
    <rule name="Imported Rule 3" stopProcessing="true">
      <match url=".?" ignoreCase="false" />
      <action type="Rewrite" url="foo/app.php" />
    </rule>
  </rules>
</rewrite>

There might be a better way with variables but I only used the IIS URL Rewrite with imports from mod_rewrite. So I don't know the syntax for those :)

Rik
  • 31
  • 4
  • if i'm running from a directory in the root, let say __foo__ how i need to format the rule to work that way – Rafael Aug 02 '13 at 15:54
0

Or you can install the isapi rewrite - no need to translate - http://www.helicontech.com/isapi_rewrite/

MrFlo
  • 335
  • 3
  • 8