WP Rewrite url for nginx

http://efreedom.com/Question/1-3491258/Multi-Site-Wordpress-Rewrite-Rules-Nginx

 

server

{


    server_name 

*.

example

.

com

;

  
    listen 

80

;


    

#on server block


    

##necessary if using a multi-site plugin


    server_name_in_redirect off

;


    

##necessary if running Nginx behind a reverse-proxy


    port_in_redirect off

;


    access_log 

/

var

/

log

/

nginx

/

example

-

com

-

access

.

log

;



    location 

/

 

{


        root   

/

var

/

www

/

example

.

com

/

wordpress

;


        index  index

.

html index

.

htm index

.

php

;


        rewrite 

^.*/

files

/(.*)

$ 

/

wp

-

includes

/

ms

-

files

.

php

?

file

=

$1 

last

;


        

if

 

(!-

e $request_filename

)

 

{


            rewrite 

^.+/?(/

wp

-.*)

 $1 

last

;


            rewrite 

^.+/?(/.*\.

php

)

$ $1 

last

;


            rewrite 

^(.+)

$ 

/

index

.

php

?

q

=

$1 

last

;


        

}


    

}



    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 

/

var

/

www

/

example

.

com

/

wordpress

;


        rewrite 

^

/.*(/

wp

-.*/.*\.(

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

))

$ $1 

last

;


        rewrite 

^.*/

files

/(.*(

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

))

$

/

wp

-

includes

/

ms

-

files

.

php

?

file

=

$1 

last

;


        expires 

30d

;


        

break

;


    

}



    location 

~

 wp

\-.*\.

php

|

wp

\-

admin

|\.

php$ 

{


        include 

/

etc

/

nginx

/

fastcgi_params

;


        fastcgi_pass  

127.0

.

0.1

:

9000

;


        fastcgi_index index

.

php

;


        fastcgi_param  SCRIPT_FILENAME  

/

var

/

www

/

example

.

com

/

wordpress$fastcgi_script_name

;


    

}




}





http://www.yeeann.com/archives/104.html



How to:Nginx rewrite rules for WordPress Multi-Site

在WordPress 3.0中,如果你想启用Multi-Site的功能,是需要对WebServer做一些必要的rewrite rules设置的。如果你用的是Apache,只需要把安装WordPress时生成的rewrite rules复制到Apache的配置文件即可。如果是使用Nginx作为WebServer,可以参考下面的rewrite规则,经过某的测试基本没问题。

rewrite ^.*/files/(.*)$ /wp-includes/ms-files.php?file=$1 last; rewrite ^(.*)?(/wp-(content|admin|includes)/.*) $2 last; rewrite ^(.*)?(/wp-.*\.php)$ $2 last;

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

需要完善的地方有待改进...

标签:  Nginx

rewrite ^.*/files/(.*)$ /wp-includes/ms-files.php?file=$1 last; rewrite ^(.*)?(/wp-(content|admin|includes)/.*) $2 last; rewrite ^(.*)?(/wp-.*\.php)$ $2 last;

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

你可能感兴趣的:(nginx,WordPress,PHP,CSS,Apache)