mod_rewrite条件,如果文件退出不起作用

时间:2015-09-17 15:30:33

标签: apache .htaccess mod-rewrite

我的conf文件中有以下条件:

RewriteCond %{REQUEST_URI} ^/export/.*$
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteRule .* /opencms/handle404?exporturi=%{REQUEST_URI}&%{QUERY_STRING} [P]

当我请求以下文件时:

http://www.somedomain.com/export/system/galleries_guardsman/pics/FPP/pencil-graphic-make-a-claim.png

我可以在重写日志中看到它符合上述条件:

RewriteCond: input='/export/system/galleries_guardsman/pics/FPP/pencil-graphic-make-a-claim.png' pattern='^/export/.*$' => matched
RewriteCond: input='/val/data/webapps/opencms/export/system/galleries_guardsman/pics/FPP/pencil-graphic-make-a-claim.png' pattern='!-f' => matched
rewrite '/export/system/galleries_guardsman/pics/FPP/pencil-graphic-make-a-claim.png' -> '/opencms/handle404?exporturi=/export/system/galleries_guardsman/pics/FPP/pencil-graphic-make-a-claim.png&'

但文件/val/data/webapps/opencms/export/system/galleries_guardsman/pics/FPP/pencil-graphic-make-a-claim.png 实际存在,因此不应调用RewriteRule。

我确信我错过了一些东西,但不知道是什么......任何帮助或见解都会非常感激。

1 个答案:

答案 0 :(得分:2)

使用:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^export/ /opencms/handle404?exporturi=%{REQUEST_URI} [QSA,P]

没有%{DOCUMENT_ROOT}

添加[QSA]以附加QUERY_STRING。