Tricky Rewrite rules.

Hone developerhondev at gmail.com
Wed Nov 21 00:31:11 MSK 2007


Ok so the apache rewrite rules are basically saying this.

If its not a search (s=.) redirect the wordpress permalink to the static
html file.

If there's not a cookie with comment_author_ in it redirect the
wordpress permalink to the static html file.

If there's not a cookie with wordpressuser, wp-postpass_ etc

Wouldn't something more like this be the way to do it:

 if ($query_string !~ ".*s=.*") { 
 rewrite ^(.*) /wp-content/cache/supercache/$http_host/$1index.html;
 }
 
 if ($http_cookie !~ "^.*comment_author_.*$" ) {
 rewrite ^(.*) /wp-content/cache/supercache/$http_host/$1index.html;
}

 if ($http_cookie !~ "^.*wordpressuser.*$" ) {
 rewrite ^(.*) /wp-content/cache/supercache/$http_host/$1index.html;
}

 if ($http_cookie !~ "^.*wp-postpass_.*$" ) {
 rewrite ^(.*) /wp-content/cache/supercache/$http_host/$1index.html
break;
}


On Sun, 2007-11-18 at 17:54 +0100, Gustavo Barrón wrote:
> 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.
-- 
http://www.honewatson.com






More information about the nginx mailing list