rewrite rules cms phpwcms not working

Francis Daly francis at
Mon Feb 16 20:37:26 UTC 2015

On Sun, Feb 15, 2015 at 09:02:05AM -0500, dansch8888 wrote:

Hi there,

I've not tried to use phpwcms. But from the apache config and your
description, I think that the following provides some of the information
to the php interpreter that it wants.

> (track|include|img|template|picture|filearchive|content|robots\.txt|favicon\.ico)($|/)
> - [L]

I think that say "anything that matches that pattern should be served
as a plain file, and not given to the php interpreter". But there are
also .htaccess files in some of those directories.

So, after you are happy that the thing you want to be working is working
on your test system, add entries like

  location ^~ /track/ {}
  location ^~ /filearchive/ { deny all; }

to your server{} block, according to what you want, before you make it public.

> RewriteRule ^ index\.php$ - [L]
> RewriteCond %{REQUEST_FILENAME} !-f
> RewriteCond %{REQUEST_FILENAME} !-d
> RewriteRule ^
> ([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.html$
> /index.php?id=$1,$2,$3,$4,$5,$6&%{QUERY_STRING}
> RewriteRule ^ (.+)\.html$ /index.php?$1&%{QUERY_STRING}
> Rewrite should do for example this:
> http://hometest.home.local/home_de.html ->
> http://hometest.home.local/index.php?home_de

I think that the above rewrites to http://hometest.home.local/index.php?home_de&

If the difference (the extra &) does not matter, then all is good.

At http level, add

  map $request_uri $bit_of_qs {
    default "";
    ~/(?P<name>.*)\.html $name;

Then at server level include

  server {

    if ($request_uri ~ /(\d+)\.(\d+)\.(\d+)\.(\d+)\.(\d+)\.(\d+)\.html) {
      set $bit_of_qs "id=$1,$2,$3,$4,$5,$6";

    location / {
      try_files $uri $uri/ @index.php;

    location ~ \.php$ {
      fastcgi_pass unix:/var/run/php5-fpm.sock;
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    location @index.php {
      fastcgi_pass unix:/var/run/php5-fpm.sock;
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $document_root/index.php;
      fastcgi_param QUERY_STRING $bit_of_qs&$query_string;


Depending on your fastcgi server, you may want the "include" line after
the "fastcgi_param" lines.

> Now I'm at this stage. I believe the main problem is the "QUERY_STRING", but
> I have no idea how that get rendered.

The above sets QUERY_STRING to what I think is the same thing that your
apache config sets it to.

> I hope someone can help me with this. The phpcwms forum couldn't give me an
> answer so fare.

I don't know if the above will let everything work -- I'd expect that
it would not -- but it should push you in the right direction.

(For example: it is not immediately clear to me what should happen to
a request for /a/ -- probably the above configuration
does not do what is wanted there.)

Good luck with it,

Francis Daly        francis at

More information about the nginx mailing list