wordpress rewrite nginx

Kirill T. tkd.pub at gmail.com
Wed Nov 14 14:22:04 MSK 2007


Hone <developerhondev at ...> writes:

> 
> location /test/ {
> 
> if (!-e $request_filename) {
> rewrite ^/test/.+?(/wp-.*) /test/$1 last;
> rewrite ^/test/.+?(/.*\.php)$ /test/$1 last;
> rewrite ^/test/(.*)$  /test/index.php?q=$1  last;
> break;
> }
> 
> }
> 
> >         location ~ .php$ {...}
> 
> I have a backslash before the .php$:
> 
> location ~ \.php$ {
> 
> Also make sure you have this for static files used by the wordpress admin at
the beginning of your conf.
> 
> location ~* ^.+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|
> xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$
>         {
>                 root /home/YOURSITE/public_html;
>                 expires 30d;
>                 break;
>         }
> 
> On Sun, 2007-11-11 at 02:22 +0000, Kirill T. wrote:
> > My wordpress blog is located in subfolder. So i`m putting rewrite rule into
> > location block of subfolder. Problem is that rule wich rewrites .php files
> > conflicts with "location ~ .php$" which is higher (in server block) than
> > rewriting rule.
> > 
> > Config part:
> >         #1 
> >         location /test/ {
> >           if (!-e $request_filename) {
> >             rewrite  ^.+?(/.*\.php)$  /test$1          last;
> >             rewrite  ^.+?(/wp-.*)     /test$1          last;
> >             rewrite  ^                /test/index.php  last;
> >           }
> >         }
> >         #2
> >         location ~ .php$ {...}
> > 
> > So it passes directly second without checking 1st and we get 404 error. How i
> > can force nginx to check #1 at first or may be exists another way?
> > 
> > 
> > 

Nope.. Still doesn`t work.
With your config:
        index  index.php;
        location /test/ {
          if (!-e $request_filename) {
            rewrite ^/test/.+?(/wp-.*) /test/$1 last;
            rewrite ^/test/.+?(/.*\.php)$ /test/$1 last;
            rewrite ^/test/(.*)$  /test/index.php?q=$1  last;
            break;
          }
        }
Working:
/test/, /test/blog/, /test/blog2/, /test/wp-admin/, /test/wp-admin/index.php,
/test/blog2/wp-content/themes/default/style.css
Not working:
/test/blog2/wp-admin/*.php, /test/blog2/*.php (404 error)

Everything is working as expected, except virtual *.php files.

My .php conf:
          location ~ \.php$ {
          if (!-f $request_filename) {
            return 404; break;
          }
  				fastcgi_pass   127.0.0.1:5550;
  				fastcgi_index  index.php;
					fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
  				fastcgi_param  QUERY_STRING     $query_string;
  				fastcgi_param  REQUEST_METHOD   $request_method;
  				fastcgi_param  CONTENT_TYPE     $content_type;
  				fastcgi_param  CONTENT_LENGTH   $content_length;
  				fastcgi_param  Host             $host;
        	fastcgi_param  X-Real-IP        $remote_addr;
        	fastcgi_param  X-Forwarded-For  $proxy_add_x_forwarded_for;
        	fastcgi_param  REQUEST_URI $request_uri;
				}
I can`t understand, how to make it to check firstly /test/ location and .php
after it. 






More information about the nginx mailing list