Tricky Rewrite rules.

Gustavo Barrón lists at ruby-forum.com
Wed Nov 21 01:16:18 MSK 2007


Hone wrote:
> 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;
> }
Well that does work, if first the file exists. But before that I have to 
check for the existence of the file with a if, but I cant have recursive 
if's. Handling the string's and queries is not difficult, But Im having 
problems after doing the if's for query's and cookies.

To be more specific:

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

Aparently sometimes does work, other gives weird 404's and 500's.
-- 
Posted via http://www.ruby-forum.com/.





More information about the nginx mailing list