我假设这对于任何有nginx知识的人来说都是一件容易的事情。
我打电话这样的URL:
/site-preview/css/custom-styles.css?org=myorg
custom-styles.css文件实际上并不存在。 所以,我想重写URL来实际服务这个:
/css/custom-styles.php?org=myorg
我来自Apache世界,我有这个工作在我的.htaccess文件。
在我的nginxconfiguration中,我尝试了如下的东西:
location /site-preview { rewrite ^/site-preview/css/custom-styles.css?(.*) /css/custom-styles.php?$1 last; }
和:
location /site-preview { rewrite ^css/custom-styles.css?(.*) /css/custom-styles.php?$1 last; }
以及在location块之外进行rewrite 。
提前致谢。
重写的nginx文档( http://nginx.org/en/docs/http/ngx_http_rewrite_module.html )指出,除非用“?”结束replacestring。 所有以前的qstringvariables被追加。 这意味着你不需要(也可能不应该)添加你的qstringvariables到replace。
另外,我会特定于我可以在位置(添加../css/ ..path:
location /site-preview/css { # this is a blind rewrite passing qstr along rewrite custom-styles.css /css/custom-styles.php last; # this one does NOT pass along qstr (using the trailing '?') rewrite custom-styles.css /css/custom-styles.php? last; }