rewrite question - "(css/js).php" to "(.css/.js)"

Francis Daly francis at
Sun Oct 24 15:31:01 MSD 2010

On Sat, Oct 23, 2010 at 10:30:41PM -0400, voku wrote:

Hi there,

> for example I want to rewrite ... this ->
> to...
> -----------------------
> I had experiment with this rule...
>         [code]
> ## Optimierung - "(css/js).php" to "(css/js)"
>         location /wp-content/plugins/wp-special-textboxes/css/ {
>                 if ($args ~ "ver=(.*)") {
>                         rewrite ^/?(.*)
> $scheme://$host/wp-content/cache/wp-special-textboxes.css permanent;
>                 }
>         }

> but this only rewrite 
> to....
> -----------------------
> Can someone please help me, thx! :-)

If the question is "how do I avoid the ?ver=3.0.1 in the rewritten
output", suggests adding
"?" as the last character of the rewrite rule. Possibly the shorter rule

  rewrite ^ /wp-content/cache/wp-special-textboxes.css? permanent;

would do, but you can experiment with the other changes to see if they
suit your setup. (nginx fills in a scheme://host in this case.)

If the question is "why is
apparently not processed by this rule", the output you do see should give
a hint, and should explain
why it happens. Possibly you want to add "^$" after the "location" word.

> I have a second problem with the rewrite... I use varnish on port 80 and
> nginx on port 8080, but some files from my WordPress-Theme want to use
> something like this "@import
> ""
> ...
> ... can someone say me how to rewrite the port to 80, thx!?!?  :-)

If you really want to rewrite in nginx, look into modules with names like

I think you're better off finding what is writing the thing you don't
want, and getting it to stop. So, check the WordPress-Theme and see
what it is doing. Either disable the scheme://host:port bit altogether
(since the browser knows to use the same scheme://host for subsequent
requests), or see where it gets its information from and change it. At
a guess, the fastcgi_params SERVER_PORT and SERVER_NAME, or HTTP_HOST
that gets sent to the php interpreter, are probably involved.

Good luck with it,

Francis Daly        francis at

More information about the nginx mailing list