nginx wordpress link (url pseudo static) 301 permanent Redirection Implementation Method _nginx

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.