Tricky Rewrite rules.

Gustavo Barrón lists at ruby-forum.com
Sun Nov 18 19:54:04 MSK 2007


Hi,

I was in need of some advice. I wanted to use a new cache plugin for
Wordpress, that writes static files. But I can't setup the rules.

The original .htaccess is something like this:
-----------------
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} !.*s=.*
RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$
RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$
RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond
%{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1index.html.gz
-f
RewriteRule ^(.*)
/wp-content/cache/supercache/%{HTTP_HOST}/$1index.html.gz [L]

RewriteCond %{QUERY_STRING} !.*s=.*
RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$
RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$
RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$
RewriteCond
%{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1index.html
-f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1index.html
[L]
-----------------

Somehow I ended with this rules...

-----------------
  location / {
    root        /var/www/mydomain.com/htdocs;
    index      index.html index.php;

    if ($request_uri ~* ".*s=.*") { rewrite ^(.*)$  /index.php$1  break;
}
    if ($http_cookie ~* "^.*comment_author_.*$" ) { rewrite ^(.*)$
/index.php?q=$1 break; }
    if ($http_cookie ~* "^.*wordpressuser.*$" ) { rewrite ^(.*)$
/index.php?q=$1  break; }
    if ($http_cookie ~* "^.*wp-postpass_.*$" ) { rewrite ^(.*)$
/index.php?q=$1 break; }
    if ($http_cookie ~* "^.*wordpressuser.*$" ) { rewrite ^(.*)$
/index.php?q=$1 break; }
    if (-f /wp-content/cache/supercache/mydomain.com/$1index.html ) {
      rewrite ^(.*)$
/wp-content/cache/supercache/mydomain.com/$1index.html last;
    }

    if (!-e $request_filename) {
      rewrite ^(.*)$  /index.php?q=$1  last;
    }
  }

-----------------

I ommited the Gzip comprobation, mostly because I couldn't find how to
verify the support on the client.

Between all my iterations of the config I have encountered many weird
stuff, like getting 404's, 500 and sometimes it returns the php directly
instead of sending to the fcgi service.

Anyway thanks for taking time to get to the bottom of this mail in the
sea of mails in the mailing list and thanks in advance for any advise.
-- 
Posted via http://www.ruby-forum.com/.





More information about the nginx mailing list