WordPress Link (url pseudo-static) in Nginx 301 permanent redirection Implementation Method

Source: Internet
Author: User

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

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.