Nginx rewrite rewrite rules examples and considerations

Source: Internet
Author: User
Keywords Nginx rewrite rule example
Tags .url aliyun can make configuration example examples forum html

Rewrite rewrite rules can make the site URL look very brief, search engine friendly, benefit to http://www.aliyun.com/zixun/aggregation/8331.html "" > site users bring memory convenience, Bring more traffic to the site.

So it's important to write Web rewrite rules. Nginx's rewrite rules are very powerful, the following is the actual use of the landlord some of the most examples of configuration to give you reference.

Note Write to location inside, otherwise $request_filename find wrong path, invalid
Location/{
root/home/freeworm/www/nginx.com.cn;
Index index.php index.html index.htm;
if (!-e $request _filename) {
Rewrite ^/pic/(. *) \.png siteimage.php?q=$1 last;
Rewrite ^/pic/(. *)/siteimage.php?q=$1 last;
Rewrite ^/([^/]*)/(. *) $/main.php?q=$1&force=$2 last;
Rewrite ^/(. *) $/main.php?q=$1 last;
Rewrite ^/$/main.php last;
Break;
}
}

if (!-f $request _filename) {
Rewrite ^/[^./]*_ ([0-9]+) \.html$/index.php?bookid=$1;
Rewrite ^/[^./]*_ ([0-9]+) $/index.php?cat=$1;
Rewrite ^/[^./]*tag ([0-9]+) $/index.php?tag=$1;
Rewrite ^/[^./]*-([0-9]+)-([0-9]+) $/index.php?cat=$1&page=$2;
Rewrite sitemap.xml/sitemap.php;
Break;
}

if (!-f $request _filename) {
Rewrite ^/pxy_ (. *)/proxy/index.php?q=$1;
}

The following are the Nginx rewrite rules for the Discuz forum:

Rewrite ^/archiver/(fid|tid)-[\w\-]+\.html) $ archiver/index.php?$1;
Rewrite ^/forum-([0-9]+)-([0-9]+) \.html$ forumdisplay.php?fid=$1&page=$2;
Rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+) \.html$ viewthread.php?tid=$1&extra=page\%3d$3&page=$2;
Rewrite ^/space-(username|uid)-(. +) \.html$ space.php?$1=$2;
Rewrite ^/tag-(. +) \.html$ tag.php?name=$1;

Rewrite ^/forum-([0-9]+)-([0-9]+) \.html$/forumdisplay.php?fid=$1&page=$2 last;

From Nginx Chinese web: http://www.nginx.com.cn/?p=341

Related Article

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.