Problem:
In several blog programs toss the results ~
Causes the URL to change two consecutive times. This is the third time.
Nginx through rewrite use "permanent;" The parameter is 301 permanent URL redirection.
The previous URL structure
http://www.jb51.net/post/199/
The URL structure you need now
Http://www.jb51.net/archives/199.html
Process:
Learn Nginx configuration rules, learn regular expressions (I have not contacted, learn Bai.) )
Nginx's Chinese Veken: http://wiki.nginx.org/NginxChs
Getting Started with regular expressions: 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
The simple explanation (earnest study regular expression-I did not study seriously ^_^):
^ Represents the beginning of a matching string.
$ indicates the end of the matching string.
$ $ represents a variable
([0-9]+) represents at least 1 numeric strings with a maximum of no restrictions.
The head looks dizzy (not the programmer.) )。 Writes out an expression.
—————————————————-
—————————————————-
Copy Code code as follows:
<a class= "title=" rewrite under href= "St_tag internal_tag http://www.iamle.com/archives/tag/rewrite" >rewrite</A> ^/post/([0-9]+)/$/archives/$1.html Permanent;
<a class= "title=" rewrite under href= "St_tag internal_tag http://www.iamle.com/archives/tag/rewrite" >rewrite</A> ^/html/y2009/([0-9]+). html$/archives/$1.html Permanent;
Add an expression to the Nginx conf file.
—————————————————–
Location/{
Put it here.
}
—————————————————-
Complete configuration:
This is my complete wordpress nginx rewrite rule configuration.
1, nginx rewrite URL change 301 redirect.
2, Nginx rewrite iamle.cn redirect to Www.jb51.net.
3, nginx WordPress rewrite pseudo static rules (to support WordPress custom URL).
Copy Code code as follows:
Location/{
Rewrite ^/post/([0-9]+)/$/archives/$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/can be jumped to http://www.jb51.net/archives/199.html