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

Francis Daly francis at daoine.org
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 ->
> 
> http://suckup.de/wp-content/plugins/wp-special-textboxes/css/wp-special-textboxes.css.php?ver=3.0.1
> 
> to...
> 
> http://suckup.de/wp-content/cache/wp-special-textboxes.css
> 
> -----------------------
> 
> 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;
>                 }
>         }
<snip>

> but this only rewrite 
> 
> http://suckup.de/wp-content/plugins/wp-special-textboxes/css/?ver=3.0.1
> 
> to....
> 
> http://suckup.de/wp-content/cache/wp-special-textboxes.css?ver=3.0.1
> 
> -----------------------
> 
> Can someone please help me, thx! :-)

If the question is "how do I avoid the ?ver=3.0.1 in the rewritten
output", http://wiki.nginx.org/HttpRewriteModule#rewrite 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
http://suckup.de/wp-content/plugins/wp-special-textboxes/css/wp-special-textboxes.css.php?ver=3.0.1
apparently not processed by this rule", the output you do see should give
a hint, and http://wiki.nginx.org/HttpCoreModule#location 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
> "http://suckup.de:8080/blog/2010/07/26/webseiten-analyse/?mystique=css"
> ...
> ... 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
"substitution"

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,

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list