2

Iirfv2.0を使用しています。

私は次のディレクトリ構造を持っています:

/
/library
/library/index.php
/webroot
/webroot/images
/Iirf.ini

アプリケーションを含むライブラリフォルダー、webrootフォルダー(画像、スタイルシートなどを含む)、およびIirf.ini構成ファイルがある場合。

ファイルがwebrootの下に存在しない場合、すべてのリクエストを/library/index.phpにリダイレクトしたいと思います。

例えば:

Request             Response
/images/blah.png -> /webroot/images/blah.png
/news            -> /library/index.php

私のIirf.ini構成には次のものがあります。

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /library/index.php [L]

これはすべてをリダイレクトしますが、webrootの下/library/index.phpに存在するかどうかを確認する方法を見つけるのに問題があります。REQUEST_FILENAME

この質問を見ましたが、にアクセスできませんDOCUMENT_ROOT。それは私に次のことを与えます(ログから取得):

Thu Jul 15 11:46:21 -   760 - ReplaceServerVariables: VariableName='REQUEST_FILENAME' Value='C:\web\favicon.ico'
Thu Jul 15 11:46:21 -   760 - ReplaceServerVariables: in='%{DOCUMENT_ROOT}/webroot/%{REQUEST_FILENAME}' out='DOCUMENT_ROOT/webroot/C:\web\favicon.ico'

どんな助けでも大歓迎です。

---編集-

ティムのより多くの読書と提案の後に私の設定を更新しました:

RewriteCond $0 !^/webroot
RewriteRule ^.*$ /webroot$0 [I]

RewriteCond $0 !-f
RewriteRule ^/webroot/(.*)$ /library/index.php [I,L,QSA]

そして、それは正しく渡され/library/index.phpますが、それでも既存のファイルをチェックしません(そうしているように見えますが)。

Thu Jul 15 14:47:30 -  3444 - EvalCondition: checking '/webroot/images/buttons/submit.gif' against pattern '!-f'
Thu Jul 15 14:47:30 -  3444 - EvalCondition: cond->SpecialConditionType= 'f'
Thu Jul 15 14:47:30 -  3444 - EvalCondition: Special: it is not a file

フィルタの作成者に連絡する必要があると思います。

4

2 に答える 2

1

うーん...私は前にIIRFについて聞いたことがありませんでした。ドキュメントを参照して と の違いを確認した後、mod_rewrite試すことができることが 2 つあります。

1つ目は、見つけた答えを交換すること%{DOCUMENT_ROOT}です。は Apache サーバー変数であり、対応する IIS 変数は. IIRF のドキュメントに基づいて、この変数が利用可能であることは知っていますが、サイトのルートを指しているかどうかは 100% 確信が持てません。%{APPL_PHYSICAL_PATH}DOCUMENT_ROOTAPPL_PHYSICAL_PATH

もう 1 つは、次のことを行うことです。ドキュメントを正しく理解しているかどうか、index.phpファイルが要求を処理するために関連するパス情報を取得する方法、およびその他の多くのことに基づいて、これも機能する場合と機能しない場合があります。確かに、これは理想的な解決策とは言えないと思いますが(私が最初に考えていた方法と比較してmod_rewrite)、うまくいくかもしれません:

RewriteEngine ON

# This should rewrite to /webroot/whatever then restart the ruleset,
# apparently...On Apache in a per-dir context, this would alter the
# %{REQUEST_FILENAME} for the next run-through. I'm assume it does
# here too, but I might be wrong.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI}      !^/webroot
RewriteRule ^.*$ /webroot/$0

# The file still doesn't exist, rewrite it back to its original form,
# but move on to the next rule instead of restarting processing. This
# may not even be necessary, but I was hoping this rewrite would have
# side-effects that would make it as if the above rewrite didn't happen.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(/webroot/)?(.*)$ $0 [NI]

# Now, if it still doesn't exist, we'll rewrite it to our
# /library/index.php file, but this may not work based on how you
# get the original request information. Adding the [U] flag will 
# create a new header that preserves the "original" URL (I'm not
# sure what it takes the value from if the URL has already been
# rewritten in a previous step), which might be useful.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ /library/index.php
于 2010-07-15T12:49:30.383 に答える
0

結局、 Helicon Tech ISAPI_Rewrite 3フィルターを使用するように切り替える必要がありました。

私が最終的に使用したhtaccessファイルは次のとおりです。

RewriteEngine On

# Check whether the file exists and if not, check whether the request starts
# with webroot. Prepend webroot if it doesn't.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI}      !^webroot
RewriteRule ^.*$ webroot/$0 [NI]

# Check whether the file exists, if not, send the request off to library/index.php
RewriteCond %{DOCUMENT_ROOT}/$0 !-f
RewriteRule ^(webroot/)?(.*)$ library/index.php [I,L,QSA]
于 2010-07-19T09:37:07.680 に答える