# Rewrite question - "(css/js).php" to "(.css/.js)"

**URL:** <https://www.ruby-forum.com/t/rewrite-question-css-js-php-to-css-js/197991>\
**Category:** NGINX\
**Created:** [October 24, 2010, 4:32am UTC](https://www.ruby-forum.com/t/rewrite-question-css-js-php-to-css-js/197991 "2010-10-24T04:32:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![okkezSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Post date:** [October 24, 2010, 4:32am UTC](https://www.ruby-forum.com/t/rewrite-question-css-js-php-to-css-js/197991/1 "2010-10-24T04:32:09Z")

</div>

Hi, I want to speed up my WordPress-Blog and so I want to cache  
“css.php”, “js.php” files to “.css”, “.js”

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](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](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;  
}  
}  
location /wp-content/plugins/wp-special-textboxes/js/ {  
if ($args ~ "ver=(._)") {  
rewrite ^/?(._)  
$scheme://$host/wp-content/cache/wstb.js permanent;  
}  
}  
[/code]

but this only rewrite

[http://suckup.de/wp-content/plugins/wp-special-textboxes/css/?ver=3.0.1](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](http://suckup.de/wp-content/cache/wp-special-textboxes.css?ver=3.0.1)

* * *

Can someone please help me, thx! 🙂

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](http://suckup.de:8080/blog/2010/07/26/webseiten-analyse/?mystique=css)”  
…  
… can someone say me how to rewrite the port to 80, thx??? 🙂

Mfg  
Voku

Posted at Nginx Forum:

> **[rewrite question - "(css/js).php" to "(.css/.js)"](https://forum.nginx.org/read.php?2,143927,143927#msg-143927)**
>
> Hi, I want to speed up my WordPress-Blog and so I want to cache "css.php", "js.php" files to ".css", ".js" for example I want to rewrite ... this -\>...

---

<div class="post-metadata">

**Author:** ![voku](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/e36b37/32.png) [@voku](https://www.ruby-forum.com/u/voku)\
**Post date:** [October 24, 2010, 1:32pm UTC](https://www.ruby-forum.com/t/rewrite-question-css-js-php-to-css-js/197991/2 "2010-10-24T13:32:09Z")

</div>

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

Hi there,

> 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;  
> }  
> }

> Can someone please help me, thx! 🙂  
> If the question is “how do I avoid the ?ver=3.0.1 in the rewritten  
> output”, [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](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](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 [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](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](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 D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![voku](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/e36b37/32.png) [@voku](https://www.ruby-forum.com/u/voku)\
**Post date:** [October 24, 2010, 6:00pm UTC](https://www.ruby-forum.com/t/rewrite-question-css-js-php-to-css-js/197991/3 "2010-10-24T18:00:08Z")

</div>

Hi, thx for the help… 🙂 … this is what I made →

```
[code]

```

## Optimierung - “(css/js).php” to “(css/js)”

```
    location /wp-content/plugins/wp-special-textboxes/css/ {
            location ~* \.(css.php)$ {
                    if ($args ~* ver=(.*)$) {
                            rewrite ^

```

$scheme://$host/wp-content/cache/wp-special-textboxes.css? permanent;  
}  
}  
}  
location /wp-content/plugins/wp-special-textboxes/js/ {  
location ~\* .(js.php)$ {  
if ($args ~\* ver=(.\*)$) {  
rewrite ^  
$scheme://$host/wp-content/cache/wstb.js? permanent;  
}  
}  
}  
[/code]

and a second thx for the tip with the “SERVER\_PORT” 🙂 … I found this  
in the theme …

```auto
$pageURL .=
$_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$request;
```

und changed it to …

```auto
$pageURL .= $_SERVER["SERVER_NAME"].":80".$request;
```

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,143927,144072#msg-144072](http://forum.nginx.org/read.php?2,143927,144072#msg-144072)
