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