WordPress MU rewrite rules

Hi

I use this rules with apache mod_rewrite

RewriteEngine On
RewriteBase /

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

RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . -
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.) $2
RewriteRule ^([_0-9a-zA-Z-]+/)?(.
.php)$ $2
RewriteRule . index.php

and this on nginx

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

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

but, dont work fine… any help?? THANKS!!!

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,8334,8334#msg-8334

First…

2009/10/8 pepejose [email protected]

   server{
           listen *:80;
           #mod rewrite wordpress

             rewrite ^.*/files/(.*) /wp-content/blogs.php?file=$1;
                     if (!-e $request_filename) {
                           rewrite ^.+?(/wp-.*) $1 last;
                           rewrite ^.+?(/.*\.php)$ $1 last;
                           rewrite ^ /index.php last;
                     }

you don’t need that

   #Proxy the PHP scripts to Apache listening on 127.0.0.1:8080
   location ~ \.php$ {
                   proxy_set_header Host $host;
                   proxy_set_header X-Real-IP $remote_addr;
                   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                   proxy_pass   http://127.0.0.1:8080;
   }
   }

If you are proxy to apache, you don’t need rewrite in nginx but only
rules in .htaccess for apache. set up nginx for static content only.

On Thu, Oct 8, 2009 at 9:46 PM, pepejose [email protected] wrote:

        #necessary if running Nginx behind a reverse-proxy
            port_in_redirect off;

        # This will reject all external requests for files with names beginning with . (dot).
        location ~ /. {
            deny  all;
        }

        #mod rewrite wordpress

  • Â Â Â Â Â Â Â Â Â rewrite ^./files/(.) /wp-content/blogs.php?file=$1;
  • Â Â Â Â Â Â Â Â Â Â Â Â Â if (!-e $request_filename) {
  • Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â rewrite ^.+?(/wp-.*) $1 last;
  • Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â rewrite ^.+?(/.*.php)$ $1 last;
  • Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â rewrite ^ /index.php last;
  • Â Â Â Â Â Â Â Â Â Â Â Â Â }
  •  try_files $uri $uri/ @apach;
    
  •  location @apach {
    
  •                    proxy_set_header Host $host;
    
  •                    proxy_set_header X-Real-IP $remote_addr;
    
  •                    proxy_set_header X-Forwarded-For
    

$proxy_add_x_forwarded_for;

  •                    proxy_pass   http://127.0.0.1:8080;
    
  •    }

If you are proxy to apache, you don’t need rewrite in nginx but only
rules in .htaccess for apache. set up nginx for static content only.

Yes, but this way I have to load the mod_rewrite apache and I want to
load only the necessary modules on apache.

sorry but I do not understand your solution.

many thanks to the two

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,8334,12295#msg-12295

I can not fix it, this is my actual setup, i tried everything I found
on google

server{
listen *:80;
server_name subdomain.domain.com;
root /xx/xxx/xxxx/;
index index.php index.html index.htm;

      #necessary if using a multi-site plugin
  server_name_in_redirect off;
      #necessary if running Nginx behind a reverse-proxy
  port_in_redirect off;

# This will reject all external requests for files with names 

beginning with . (dot).
location ~ /. {
deny all;
}

#mod rewrite wordpress

        rewrite ^.*/files/(.*) /wp-content/blogs.php?file=$1;
    if (!-e $request_filename) {
    rewrite ^.+?(/wp-.*) $1 last;
    rewrite ^.+?(/.*\.php)$ $1 last;
    rewrite ^ /index.php last;
    }

    #Proxy the PHP scripts to Apache listening on 127.0.0.1:8080
    location ~ \.php$ {
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_pass   http://127.0.0.1:8080;
    }

}

server_name_in_redirect off; and port_in_redirect off; directives have
not helped

The result is:

  • All resquests loads index (blogs planet)
  • Images of blogs generates 404…

I have analyzed this last a bit, and the problem is that for example:

http://subdomain.domain.com/userblog/files/2008/04/image.jpg ==
http://subdomain.domain.com/wp-content/blogs.php?file=2008/04/image.jpg

the result is -> 404 — File not found.

because do not select fine the id of the blog, id take it out of the
database according to userblog, isn´t it? in that case ‘/userblog/’ lost
when apply the rewrite rule!!

http://subdomain.domain.com/wp-content/blogs.dir/ correct IdBlog is 2 to
this userblog but always is 1 /files/2008/04/image.jpg

I’m going crazy, please help!

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,8334,12091#msg-12091

I’ve similar error with wordpress mu configured on nginx + fastcgi

if I enabled permalink in this format:
/%year%/%monthnum%/%day%/%postname%/
(es. http://test.mydomain.tld/2009/10/20/test02/) i received every time
the same page, if i configured permalinks in the default format every
think works fine (for example: http://test.mydomain.tld/?p=123))

This is my configuration:
server {
listen 80;
server_name test.mydomain.tld;

access_log /var/log/nginx/test.mydomain.tld.log;
error_log /var/log/nginx/test.mydomain.tld.error.log;
error_log /var/log/nginx/test.mydomain.tld.error.log
notice;
rewrite_log on;

location / {
root /var/www/test.mydomain.tld;
index index.php index.html index.htm;

if (-f $request_filename) {
  expires 30d;
  break;
       }

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

             if (!-e $request_filename) {
  rewrite ^ /index.php last;
             }
   }

location ~ .php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass fcgi5;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/var/www/test.mydomain.tld$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT
/var/www/test.mydomain.tld/;
}
}

This is the rewrite logs:
2009/10/20 11:57:45 [notice] 3183#0: 17 "^./files/(.*)" does not match
“/2009/10/20/test01/”, client: 192.168.251.27, server:
drupal.lantians.net, request: “GET /2009/10/20/test01/ HTTP/1.1”, host:
drupal.lantians.net”, referrer: “http://drupal.lantians.net/
2009/10/20 11:57:45 [notice] 3183#0: *17 “^” matches
“/2009/10/20/test01/”, client: 192.168.251.27, server:
drupal.lantians.net, request: “GET /2009/10/20/test01/ HTTP/1.1”, host:
drupal.lantians.net”, referrer: “http://drupal.lantians.net/
2009/10/20 11:57:45 [notice] 3183#0: *17 rewritten data: “/index.php”,
args: “”, client: 192.168.251.27, server: drupal.lantians.net, request:
“GET /2009/10/20/test01/ HTTP/1.1”, host: “drupal.lantians.net”,
referrer: “http://drupal.lantians.net/

Any ideas ?
Daniele

Edho P Arief ha scritto:

On Fri, Oct 9, 2009 at 2:14 PM, pepejose [email protected] wrote:

sorry but I do not understand your solution.

many thanks to the two

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,8334,12295#msg-12295

here’s the config I tried and seems to be working:
http://pastebin.com/m40212ee1

replace

include php_params;

with

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080;

like this http://pastebin.com/m1ea4181e

but I’m not sure if it works with apache backend…

On Tue, Oct 20, 2009 at 9:03 PM, Daniele M. [email protected] wrote:

I’ve similar error with wordpress mu configured on nginx + fastcgi

if I enabled permalink in this format: /%year%/%monthnum%/%day%/%postname%/
(es. http://test.mydomain.tld/2009/10/20/test02/) i received every time the
same page, if i configured permalinks in the default format every think
works fine (for example: http://test.mydomain.tld/?p=123))

what version is your wp(-mu)?

Edho P Arief ha scritto:

what version is your wp(-mu)?

WordPress MU 2.8.4.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs