0

我对 ProcessWire 的缓存插件有一些问题,但也许这是一个关于 apache .htaccess 限制的更全球性的问题。

例子:

我这样调用我的页面:http ://example.com/foo 如果有文件,.htaccess 应该查找DOCUMENT_ROOT/cache/foo/index.html 如果文件存在,则显示该文件,或者 - 为本示例简化 - 只需调用成功页面

示例文件结构:

cache/foo/index.html (some dummy content)
bar (some dummy content)
file-found.php (the success page with some print_r($_SERVER) stuff)
.htaccess with this content:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{DOCUMENT_ROOT}/cache/$1/index.html -f
    RewriteRule ^(.*) file-found.php
</IfModule>

这在我的本地机器上正常工作([SERVER_SOFTWARE] => Apache/2.4.18 (Unix))但不适用于我想使用的托管包。([SERVER_SOFTWARE] => Apache/2.2.31 (Unix)) 服务器的反应只是一个 404:“在这个服务器上找不到请求的 URL /foo。”

是因为apache的版本不工作还是受主机限制?

顺便提一句。ModRewrite 基本上适用于这个主机。例如像这样:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^(.*) file-found.php
</IfModule>

如果我调用http://example.com/bar,会显示 file-found.php

任何想法如何在htaccess中解决这个“如果文件存在=>然后”规则?

感谢帮助!


编辑:更简化:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{DOCUMENT_ROOT}/bar -f
  RewriteRule ^(.*) file-found.php
</IfModule>

在本地工作,但不在主机上

4

2 回答 2

0

我认为在RewriteCond特殊字符中应该转义\(如果整个短语不在双引号中)

你有RewriteRule没有尝试添加标志,比如[L]或等等。

于 2016-10-12T07:20:47.713 回答
0

试试这个(你可能需要RewriteBase /):

RewriteCond cache%{REQUEST_URI}/index.html -f
RewriteRule ^[^/]+(?:/[^/]+)*$ cache/$0/index.html [L]
RewriteCond cache%{REQUEST_URI}index.html -f
RewriteRule ^(?:[^/]+/)*$ cache/$0index.html [L]
于 2016-10-15T16:40:53.433 回答