wordpress rewrite nginx

Igor Sysoev is at rambler-co.ru
Tue Feb 13 16:00:00 MSK 2007


On Tue, Feb 13, 2007 at 01:48:57AM +0200, Anonymous Coward wrote:

> i installed Wordpress today on nginx  and everything seems ok except one
> "small" issue, i don't know how to convert the rewrite rules.
> So if anybody has any experience or knows how to do it i'd be gratefull
> cause they have only Apache examples :(
> 
> RewriteEngine On
> RewriteBase /
> 
> # Rewrite www.domain.com to domain.com
> RewriteCond %{HTTP_HOST} ^www\.(.*)
> RewriteRule ^(.*)       http://%1/$1 [R,L]
> 
> #uploaded files
> RewriteRule ^(.*)?/?files/(.*) wp-content/blogs.php?file=$2 [L]
> 
> RewriteCond %{REQUEST_FILENAME} -f [OR]
> RewriteCond %{REQUEST_FILENAME} -d
> RewriteRule . - [L]
> RewriteRule  ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
> RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
> RewriteRule . index.php [L]


    server {
        ...

        # Rewrite www.domain.com to domain.com
        if ($http_host ~ "^www\.(.*)") {
            set      $name    $1;
            rewrite  ^(.*)    http://$name/$1;
        }

        #uploaded files
        rewrite  ^(.*)?/?files/(.*) /wp-content/blogs.php?file=$2;

        if (!-e $request_filename) {
            rewrite  ^([_0-9a-zA-Z-]+)?(/wp-.*)     $2          last;
            rewrite  ^([_0-9a-zA-Z-]+)?(/.*\.php)$  $2          last;
            rewrite  ^                              /index.php  last;
        }

        ...
    }

However, it's better to replace the first rule with separate virtual hosts.


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list