Problem:
The result of tossing in several blog programs ~
This causes the url to change twice in a row. This is the third time.
Nginx uses the "permanent;" parameter through rewrite to generate 301 permanent url redirection.
Previous url Structure
Http://www.jb51.net/post/199/
Url Structure
Http://www.jb51.net/archives/199.html
Process:
Learn nginx configuration rules and learn Regular Expressions (I have never touched any of them .)
Nginx Chinese Vico: http://wiki.nginx.org/NginxChs
Regular Expression entry: http://zh.wikipedia.org/zh-cn/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F
Http://www.jb51.net/tools/zhengze.html
Briefly explain (learn the regular expression carefully-I did not learn it seriously ^_^ ):
^ Indicates the start of matching string.
$ Indicates the end of the matching string.
$1 $2 indicates a variable
([0-9] +) indicates at least one number string with no limit.
The head is dizzy (not a programmer .). Write an expression.
------------------
------------------
Copy codeThe Code is as follows: <A class = "st_tag internal_tag" title = "log under tag rewrite" href = "http://www.iamle.com/archives/tag/rewrite" rel = tag> rewrite </A> ^/post/([0-9] +) /$/archives/Tables 1.html permanent;
<A class = "st_tag internal_tag" title = "log under tag rewrite" href = "http://www.iamle.com/archives/tag/rewrite" rel = tag> rewrite </A> ^/html/y2009/(%0-9%%%%%%.html $/ archives/Tables 1.html permanent;
Add the expression to the nginx conf file.
------------------
Location /{
Put it here.
}
------------------
Complete the Configuration:
This is my complete WordPress nginx rewrite rule configuration.
1. Change the nginx rewrite url to 301 redirection.
2. nginx rewrite iamle.cn is redirected to www.jb51.net.
3. nginx WordPress rewrite pseudo-static rules (support for WordPress custom URLs ).
Copy codeThe Code is as follows: location /{
Rewrite ^/post/([0-9] +)/$/archives/restore 1.html permanent;
Rewrite ^/html/y2009/(%0-9%%%%%.html $/archives/%1.html permanent;
If ($ host !~ "^ Www \. iamle \. com $ "){
Rewrite ^ (. *) http://www.jb51.net $1 permanent;
}
If (-f $ request_filename/index.html ){
Rewrite (. *) $1/index.html break;
}
If (-f $ request_filename/index. php ){
Rewrite (. *) $1/index. php;
}
If (! -F $ request_filename ){
Rewrite (. *)/index. php;
}
}
Test results:
Access: http://www.jb51.net/post/199/ to jump to the http://www.jb51.net/archives/199.html