如何在提供静态内容之前重写nginx来执行php文件?

时间:2015-12-01 18:59:21

标签: apache nginx rewrite

我试图在nginx中执行此操作,但我无法让它工作:

# protect images
RewriteCond %{REQUEST_FILENAME} \.(bmp|gif|ico|jpe|jpeg|jpg|png)$
RewriteRule .* /path-to-file.php [L,QSA]

使用try_filesrewrite尝试过,任何建议都表示赞赏!

1 个答案:

答案 0 :(得分:0)

要将所有图像URI重写为特定的PHP脚本,您可以使用正则表达式位置和内部重写:

location ~* \.(bmp|gif|ico|jpe|jpeg|jpg|png)$ {
  rewrite ^ /path/to/file.php;
}
相关问题