1

PHP でアプリケーションを開発するために Zend Framework 2 を使用しています。すべてがローカルで動作します (Linux の apache サーバー)。

しかし、今は自分のサイトを Windows Server に展開する必要があります (Azure 上の IIS を使用)。

IIS は .htaccess を読み取らないため、web.config ファイルに書き直す必要があります。これは、IIS7 のインポート書き換えルール機能を使用して行ったことです。詳細はこちら

残念ながら、ISS はルールを Web 構成に変換できません。

ここであなたの助けが必要です。

これが私の .htaccess ファイルです (Zend Framework 2 のデフォルトのファイル)

RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

編集

いくつかの調査の後、-s と -l (最初の 2 つの条件) を -f に置き換えることができることがわかりました。完全!

したがって、私の本当の問題は、最後の 2 つのルールに焦点を当てています。(ISS は E=.. および ENV:.. 構文を変換できます)

4

2 に答える 2

1

ZF2 ドキュメントから:

URL 書き換えモジュールで IIS を使用している場合は、以下をインポートします。

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ index.php [NC,L]

これを試しましたか?

于 2013-07-19T21:54:03.713 に答える
0

わかりましたので、これが私の最終的な解決策です。すべてが機能し、私の期待どおりです (URL に /public を見たくないという事実を追加しました)。

理解を深めるために、コードのコメントを読んでください。

<!-- Rewrite rules -->
<!-- Below is some rules in order to have a beautiful URL on the client side.
    + Each requests to a /public/something urls are transferred to a /something url
    + If the /public/requestFile exists we serve it
    + If the requested file exists  we serve it
    + If no other rules has matched then we send the request to our public/index.php file             (default behavior from Zend Framework 2)
-->
<rewrite>
  <rules>
    <!-- Permanent redirect of requests on /public/something to /something -->
    <rule name="Redirect public " stopProcessing="true">
      <match url="^public/(.*)$" ignoreCase="false" />
      <action type="Redirect" redirectType="Permanent" url="/{R:1}" />
    </rule>

     <!-- If the file/directory requested exist in /public, we serve it. -->
    <rule name="Search in public" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="false" />
      <conditions logicalGrouping="MatchAny">
        <add input="{DOCUMENT_ROOT}/public{URL}" matchType="IsFile" ignoreCase="false" />  
        <add input="{DOCUMENT_ROOT}/public{URL}" matchType="IsDirectory" ignoeCase="false" />
      </conditions>
      <action type="Rewrite" url="/public/{R:1}" />
    </rule>

    <!-- If the file/directory requested exist, we serve it. -->
    <rule name="Direct files" stopProcessing="true">
      <match url="^.*$" />
      <conditions logicalGrouping="MatchAny">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="true" />
      </conditions>
      <action type="None" />
    </rule>

    <!-- If no previous rules have matched, then we send the request to public/index (url rewriting
        used by Zend -->
    <rule name="Url rewriting" stopProcessing="true">
    <match url="^.*$" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
      </conditions>
      <action type="Rewrite" url="public/index.php" />
    </rule>
  </rules>
</rewrite>

助けてくれたルーベンに感謝します!

于 2013-07-22T15:18:25.963 に答える