2

我正在使用Iirf v2.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]

它将所有内容重定向到,/library/index.php但我无法确定如何检查REQUEST_FILENAMEwebroot 下是否存在。

我已经看过这个问题,但我无权访问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'

任何帮助将不胜感激。

---编辑--

经过更多阅读和 Tim 的建议,我更新了我的配置:

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,我有两件事可以尝试。

首先是在您找到的答案中%{DOCUMENT_ROOT}换掉。是一个 Apache 服务器变量,据我所知,相应的 IIS 变量应该是. 根据 IIRF 文档,我知道这个变量是可用的,但不可否认,我不能 100% 确定它是否指向您的站点根目录。%{APPL_PHYSICAL_PATH}DOCUMENT_ROOTAPPL_PHYSICAL_PATH

另一种是执行以下操作,根据我是否正确理解文档、您的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 回答