1

我试图禁止访问我的 webApp 中的某些文件夹,但在某处使用 index.cfm 似乎有一些例外......

对于此示例,我仅使用以下 mod_rewrite 规则:

RewriteRule ^(.*)$ index.cfm [QSA,L]

使用结果访问以下 url:

/index.cfm //->/index.cfm naturally
/test/test.html //->/index.cfm 
/test/ //->/index.cfm 
/test/test.cfm //->/index.cfm 
/test/index.cfm //->/test/index.cfm 

请注意,最后一个请求似乎忽略了重写规则,这怎么可能发生?

(除根目录下的 index.cfm 外,文件系统中不存在上述所有文件)

编辑也,.htaccess 文件放在根目录中

编辑 2我添加了一个RewriteLog看看发生了什么,肯定有区别,但我不明白为什么......

/test/index.html

[rid#15d1048/initial] (2) init rewrite engine with requested uri /test/index.html
[rid#15d1048/initial] (1) pass through /test/index.html
[rid#15d1048/initial] (3) [perdir C:/my/local/dir/] add path info postfix: C:/my/local/dir/test -> C:/my/local/dir/test/index.html
[rid#15d1048/initial] (3) [perdir C:/my/local/dir/] strip per-dir prefix: C:/my/local/dir/test/index.html -> test/index.html
[rid#15d1048/initial] (3) [perdir C:/my/local/dir/] applying pattern '^(.*)$' to uri 'test/index.html'
[rid#15d1048/initial] (2) [perdir C:/my/local/dir/] rewrite 'test/index.html' -> 'index.cfm'
[rid#15d1048/initial] (3) [perdir C:/my/local/dir/] add per-dir prefix: index.cfm -> C:/my/local/dir/index.cfm
[rid#15d1048/initial] (2) [perdir C:/my/local/dir/] strip document_root prefix: C:/my/local/dir/index.cfm -> /index.cfm
[rid#15d1048/initial] (1) [perdir C:/my/local/dir/] internal redirect with /index.cfm [INTERNAL REDIRECT]
[rid#15cb4c0/initial/redir#1] (2) init rewrite engine with requested uri /index.cfm
[rid#15cb4c0/initial/redir#1] (1) pass through /index.cfm
[rid#15cb4c0/initial/redir#1] (3) [perdir C:/my/local/dir/] strip per-dir prefix: C:/my/local/dir/index.cfm -> index.cfm
[rid#15cb4c0/initial/redir#1] (3) [perdir C:/my/local/dir/] applying pattern '^(.*)$' to uri 'index.cfm'
[rid#15cb4c0/initial/redir#1] (2) [perdir C:/my/local/dir/] rewrite 'index.cfm' -> 'index.cfm'
[rid#15cb4c0/initial/redir#1] (3) [perdir C:/my/local/dir/] add per-dir prefix: index.cfm -> C:/my/local/dir/index.cfm
[rid#15cb4c0/initial/redir#1] (1) [perdir C:/my/local/dir/] initial URL equal rewritten URL: C:/my/local/dir/index.cfm [IGNORING REWRITE]

/test/index.cfm

[rid#15ca1a0/initial] (2) init rewrite engine with requested uri /test/index.cfm
[rid#15ca1a0/initial] (1) pass through /test/index.cfm
[rid#15ca1a0/initial] (3) [perdir C:/my/local/dir/] add path info postfix: C:/my/local/dir/test -> C:/my/local/dir/test/index.cfm
[rid#15ca1a0/initial] (3) [perdir C:/my/local/dir/] strip per-dir prefix: C:/my/local/dir/test/index.cfm -> test/index.cfm
[rid#15ca1a0/initial] (3) [perdir C:/my/local/dir/] applying pattern '^(.*)$' to uri 'test/index.cfm'
[rid#15ca1a0/initial] (2) [perdir C:/my/local/dir/] rewrite 'test/index.cfm' -> 'index.cfm'
[rid#15ca1a0/initial] (3) [perdir C:/my/local/dir/] add per-dir prefix: index.cfm -> C:/my/local/dir/index.cfm
[rid#15ca1a0/initial] (2) [perdir C:/my/local/dir/] strip document_root prefix: C:/my/local/dir/index.cfm -> /index.cfm
[rid#15ca1a0/initial] (1) [perdir C:/my/local/dir/] internal redirect with /index.cfm [INTERNAL REDIRECT]
4

1 回答 1

0

不是我正在寻找的完美答案,但这就是我为获得相同结果所做的事情:

.htaccess我添加以下行以转发任何未由 railo 处理的文件:

RewriteCond %{REQUEST_URI} ^/(my|forbidden|folders)
RewriteRule ^(.*)$ /index.cfm/some/page [L]

application.cfc我添加以下行以转发 railo 处理的文件:

<cfif Find(listFirst(arguments.targetPage, "/"), "my,forbidden,folders")>
    <cfset GetPageContext().Forward("/index.cfm/some/page")>
</cfif>

这样我可以在不更改请求的 url 的情况下显示另一个页面。

我一直希望有一个解决方案,.htaccess但似乎由于树脂/apache连接中的错误,这还不能工作。

于 2012-08-07T11:14:48.430 回答