Why isn't this rewrite rule (nginx) applied? (trying to setup Wordpress multisite)
Posted
by
Brian Park
on Server Fault
See other posts from Server Fault
or by Brian Park
Published on 2010-09-15T05:43:07Z
Indexed on
2011/01/06
3:55 UTC
Read the original article
Hit count: 313
Hi, I'm trying to setup Wordpress multisite (subfolder structure) with nginx, but having a problem with this rewrite rule.
Below is the Apache's .htaccess, which I have to translate into nginx configuration.
RewriteEngine On
RewriteBase /blogs/
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
Below is what I came up with:
server {
listen 80;
server_name example.com;
server_name_in_redirect off;
expires 1d;
access_log /srv/www/example.com/logs/access.log;
error_log /srv/www/example.com/logs/error.log;
root /srv/www/example.com/public;
index index.html;
try_files $uri $uri/ /index.html;
# rewriting uploaded files
rewrite ^/blogs/(.+/)?files/(.+) /blogs/wp-includes/ms-files.php?file=$2 last;
# add a trailing slash to /wp-admin
rewrite ^/blogs/(.+/)?wp-admin$ /blogs/$1wp-admin/ permanent;
if (!-e $request_filename) {
rewrite ^/blogs/(.+/)?(wp-(content|admin|includes).*) /blogs/$2 last;
rewrite ^/blogs/(.+/)?(.*\.php)$ /blogs/$2 last;
}
location /blogs/ {
index index.php;
#try_files $uri $uri/ /blogs/index.php?q=$uri&$args;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/example.com/public$fastcgi_script_name;
}
# static assets
location ~* ^.+\.(manifest)$ {
access_log /srv/www/example.com/logs/static.log;
}
location ~* ^.+\.(ico|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
# only set expires max IFF the file is a static file and exists
if (-f $request_filename) {
expires max;
access_log /srv/www/example.com/logs/static.log;
}
}
}
In the above code, I believe rewrite ^/blogs/(.+/)?(.*\.php)$ /blogs/$2 last;
has no effect because when I look at the access_log file, I see the following line:
2010/09/15 01:14:55 [error] 10166#0: *8 "/srv/www/example.com/public/blogs/test/index.php" is not found (2: No such file or directory), request: "GET /blogs/test/ HTTP/1.1"
(Here, 'test' is the second blog created using multisite feature) What I'm expecting is that /blogs/test/index.php gets rewritten to /blogs/index.php, but it doesn't seem to do that...
Am I overlooking something obvious?
Thanks!
© Server Fault or respective owner