我在Windows上使用 Apache 2.4.7 (问题似乎在Apache 2.2中不存在)。我有一个内部重定向到预渲染文件的问题。该文件存在于磁盘上,但不由apache输出。
在我的vhost配置中(摘录):
DocumentRoot "C:/xampp/htdocs/local.example.com/public/www.example.com/www"
DirectoryIndex index.html index.htm index.shtml index.php
在.htaccess中我有:
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{SERVER_NAME} ^(.*)\.example\.com$ NC]
RewriteCond %{DOCUMENT_ROOT}/static/filecache/prerendered/%1/index.html -f
RewriteRule .* /static/filecache/prerendered/%1/index.html [L]
文件系统中存在文件C:/xampp/htdocs/local.example.com/public/www.example.com/www/static/filecache/prerendered/local/index.html
。这也可以在日志中看到。
当我向http://local.example.com/发出请求时,重写日志中会出现以下内容:
[Fri Aug 22 10:14:51.267055 2014] [rewrite:trace2] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7d90360/initial] init rewrite engine with requested uri /
[Fri Aug 22 10:14:51.267055 2014] [rewrite:trace3] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7d90360/initial] applying pattern '^/wp-content/uploads/(.*)' to uri '/'
[Fri Aug 22 10:14:51.267055 2014] [rewrite:trace3] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7d90360/initial] applying pattern '^/wp-content/gallery/(.*)' to uri '/'
[Fri Aug 22 10:14:51.267055 2014] [rewrite:trace1] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7d90360/initial] pass through /
[Fri Aug 22 10:14:51.273055 2014] [rewrite:trace3] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7d90360/initial] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] strip per-dir prefix: C:/xampp/htdocs/local.example.com/public/www.example.com/www/ ->
[Fri Aug 22 10:14:51.273055 2014] [rewrite:trace3] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7d90360/initial] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] applying pattern '.*' to uri ''
[Fri Aug 22 10:14:51.273055 2014] [rewrite:trace4] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7d90360/initial] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] RewriteCond: input='/' pattern='^/$' => matched
[Fri Aug 22 10:14:51.273055 2014] [rewrite:trace4] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7d90360/initial] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] RewriteCond: input='local.example.com' pattern='^(.*)\\.example\\.com$' [NC] => matched
[Fri Aug 22 10:14:51.273055 2014] [rewrite:trace4] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7d90360/initial] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] RewriteCond: input='C:/xampp/htdocs/local.example.com/public/www.example.com/www/static/filecache/prerendered/local/index.html' pattern='-f' => matched
[Fri Aug 22 10:14:51.273055 2014] [rewrite:trace2] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7d90360/initial] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] rewrite '' -> '/static/filecache/prerendered/local/index.html'
[Fri Aug 22 10:14:51.273055 2014] [rewrite:trace1] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7d90360/initial] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] internal redirect with /static/filecache/prerendered/local/index.html [INTERNAL REDIRECT]
[Fri Aug 22 10:14:51.273055 2014] [rewrite:trace2] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] init rewrite engine with requested uri /index.html
[Fri Aug 22 10:14:51.273055 2014] [rewrite:trace3] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] applying pattern '^/wp-content/uploads/(.*)' to uri '/index.html'
[Fri Aug 22 10:14:51.273055 2014] [rewrite:trace3] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] applying pattern '^/wp-content/gallery/(.*)' to uri '/index.html'
[Fri Aug 22 10:14:51.273055 2014] [rewrite:trace1] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] pass through /index.html
[Fri Aug 22 10:14:51.277056 2014] [rewrite:trace3] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] strip per-dir prefix: C:/xampp/htdocs/local.example.com/public/www.example.com/www/index.html -> index.html
[Fri Aug 22 10:14:51.277056 2014] [rewrite:trace3] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] applying pattern '.*' to uri 'index.html'
[Fri Aug 22 10:14:51.277056 2014] [rewrite:trace4] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] RewriteCond: input='/index.html' pattern='^/$' => not-matched
[Fri Aug 22 10:14:51.277056 2014] [rewrite:trace1] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] pass through C:/xampp/htdocs/local.example.com/public/www.example.com/www/index.html
[Fri Aug 22 10:14:51.277056 2014] [rewrite:trace2] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] init rewrite engine with requested uri /index.htm
[Fri Aug 22 10:14:51.277056 2014] [rewrite:trace3] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] applying pattern '^/wp-content/uploads/(.*)' to uri '/index.htm'
[Fri Aug 22 10:14:51.277056 2014] [rewrite:trace3] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] applying pattern '^/wp-content/gallery/(.*)' to uri '/index.htm'
[Fri Aug 22 10:14:51.277056 2014] [rewrite:trace1] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] pass through /index.htm
[Fri Aug 22 10:14:51.289057 2014] [rewrite:trace3] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] strip per-dir prefix: C:/xampp/htdocs/local.example.com/public/www.example.com/www/index.htm -> index.htm
[Fri Aug 22 10:14:51.289057 2014] [rewrite:trace3] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] applying pattern '.*' to uri 'index.htm'
[Fri Aug 22 10:14:51.289057 2014] [rewrite:trace4] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] RewriteCond: input='/index.htm' pattern='^/$' => not-matched
[Fri Aug 22 10:14:51.289057 2014] [rewrite:trace1] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] pass through C:/xampp/htdocs/local.example.com/public/www.example.com/www/index.htm
[Fri Aug 22 10:14:51.289057 2014] [rewrite:trace2] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] init rewrite engine with requested uri /index.shtml
[Fri Aug 22 10:14:51.289057 2014] [rewrite:trace3] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] applying pattern '^/wp-content/uploads/(.*)' to uri '/index.shtml'
[Fri Aug 22 10:14:51.289057 2014] [rewrite:trace3] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] applying pattern '^/wp-content/gallery/(.*)' to uri '/index.shtml'
[Fri Aug 22 10:14:51.289057 2014] [rewrite:trace1] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] pass through /index.shtml
[Fri Aug 22 10:14:51.297058 2014] [rewrite:trace3] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] strip per-dir prefix: C:/xampp/htdocs/local.example.com/public/www.example.com/www/index.shtml -> index.shtml
[Fri Aug 22 10:14:51.297058 2014] [rewrite:trace3] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] applying pattern '.*' to uri 'index.shtml'
[Fri Aug 22 10:14:51.297058 2014] [rewrite:trace4] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] RewriteCond: input='/index.shtml' pattern='^/$' => not-matched
[Fri Aug 22 10:14:51.297058 2014] [rewrite:trace1] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] pass through C:/xampp/htdocs/local.example.com/public/www.example.com/www/index.shtml
[Fri Aug 22 10:14:51.298058 2014] [rewrite:trace2] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] init rewrite engine with requested uri /index.php
[Fri Aug 22 10:14:51.298058 2014] [rewrite:trace3] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] applying pattern '^/wp-content/uploads/(.*)' to uri '/index.php'
[Fri Aug 22 10:14:51.298058 2014] [rewrite:trace3] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] applying pattern '^/wp-content/gallery/(.*)' to uri '/index.php'
[Fri Aug 22 10:14:51.298058 2014] [rewrite:trace1] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] pass through /index.php
[Fri Aug 22 10:14:51.298058 2014] [rewrite:trace3] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] strip per-dir prefix: C:/xampp/htdocs/local.example.com/public/www.example.com/www/index.php -> index.php
[Fri Aug 22 10:14:51.298058 2014] [rewrite:trace3] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] applying pattern '.*' to uri 'index.php'
[Fri Aug 22 10:14:51.298058 2014] [rewrite:trace4] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] RewriteCond: input='/index.php' pattern='^/$' => not-matched
[Fri Aug 22 10:14:51.298058 2014] [rewrite:trace1] [pid 9860:tid 1684] mod_rewrite.c(468): [client ::1:57345] ::1 - - [local.example.com/sid#6f0978][rid#7da63b8/subreq] [perdir C:/xampp/htdocs/local.example.com/public/www.example.com/www/] pass through C:/xampp/htdocs/local.example.com/public/www.example.com/www/index.php
我想知道为什么apache正在使用/index.html
,/index.htm
,/index.shtml
和/index.php
初始化重写引擎,即使之前发生了内部重定向。不应该使用新路径(/static/filecache/prerendered/local/index.html
)在下一个循环中初始化重写引擎吗?该文件存在但不是由apache输出的。根据{{3}},路径/static/...
应作为相对于文档根目录的文件系统路径处理:
文件系统路径 指定要传递给客户端的资源的文件系统上的位置。当在服务器(虚拟主机)上下文中配置规则并且替换中的路径的第一个组件存在于文件系统中时,替换仅被视为文件系统路径 的 URL路径 要提供的资源的DocumentRoot相对路径。请注意,mod_rewrite尝试通过检查文件系统根目录中是否存在路径的第一个段来猜测您是否指定了文件系统路径或URL路径。例如,如果您指定/www/file.html的替换字符串,那么这将被视为URL路径,除非在根或您的文件系统中存在名为www的目录(或者,在使用重写的情况下)在.htaccess文件中,相对于您的文档根目录),在这种情况下,它将被视为文件系统路径。如果您希望将其他URL映射指令(例如Alias)应用于生成的URL路径,请使用[PT]标志,如下所述。
我看过http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule这个问题和答案,但我不认为我的问题在那里得到了解释。如果是的话,我似乎错过了什么。