DataLife Engine 的 Nginx 网址重写规则

# Redirects
rewrite ^<span class="regexp">/page/</span>(.*)$ /index.php?cstart=$<span class="number">1</span> last;

# Post
rewrite ^<span class="regexp">/([0-9]+)/</span>([<span class="number">0</span>-<span class="number">9</span>]+)/([<span class="number">0</span>-<span class="number">9</span>]+)/page,([<span class="number">0</span>-<span class="number">9</span>]+),([<span class="number">0</span>-<span class="number">9</span>]+),(.*).html(<span class="regexp">/?)+$ /i</span>ndex.php?subaction=showfull&year=$<span class="number">1</span>&month=$<span class="number">2</span>&day=$<span class="number">3</span>&news_page=$<span class="number">4</span>&cstart=$<span class="number">5</span>&news_name=$<span class="number">6</span> last;
rewrite ^<span class="regexp">/([0-9]+)/</span>([<span class="number">0</span>-<span class="number">9</span>]+)/([<span class="number">0</span>-<span class="number">9</span>]+)/page,([<span class="number">0</span>-<span class="number">9</span>]+),(.*).html(<span class="regexp">/?)+$ /i</span>ndex.php?subaction=showfull&year=$<span class="number">1</span>&month=$<span class="number">2</span>&day=$<span class="number">3</span>&news_page=$<span class="number">4</span>&news_name=$<span class="number">5</span> last;
rewrite ^<span class="regexp">/([0-9]+)/</span>([<span class="number">0</span>-<span class="number">9</span>]+)/([<span class="number">0</span>-<span class="number">9</span>]+)/print:page,([<span class="number">0</span>-<span class="number">9</span>]+),(.*).html(<span class="regexp">/?)+$ /</span>engine/print.php?subaction=showfull&year=$<span class="number">1</span>&month=$<span class="number">2</span>&day=$<span class="number">3</span>&news_page=$<span class="number">4</span>&news_name=$<span class="number">5</span> last;
rewrite ^<span class="regexp">/([0-9]+)/</span>([<span class="number">0</span>-<span class="number">9</span>]+)/([<span class="number">0</span>-<span class="number">9</span>]+)/(.*).html(<span class="regexp">/?)+$ /i</span>ndex.php?subaction=showfull&year=$<span class="number">1</span>&month=$<span class="number">2</span>&day=$<span class="number">3</span>&news_name=$<span class="number">4</span> last;

rewrite ^<span class="regexp">/([^.]+)/</span>page,([<span class="number">0</span>-<span class="number">9</span>]+),([<span class="number">0</span>-<span class="number">9</span>]+),([<span class="number">0</span>-<span class="number">9</span>]+)-(.*).html(<span class="regexp">/?)+$ /i</span>ndex.php?newsid=$<span class="number">4</span>&news_page=$<span class="number">2</span>&cstart=$<span class="number">3</span>&seourl=$<span class="number">5</span>&seocat=$<span class="number">1</span> last;
rewrite ^<span class="regexp">/([^.]+)/</span>page,([<span class="number">0</span>-<span class="number">9</span>]+),([<span class="number">0</span>-<span class="number">9</span>]+)-(.*).html(<span class="regexp">/?)+$ /i</span>ndex.php?newsid=$<span class="number">3</span>&news_page=$<span class="number">2</span>&seourl=$<span class="number">4</span>&seocat=$<span class="number">1</span> last;
rewrite ^<span class="regexp">/([^.]+)/</span>print:page,([<span class="number">0</span>-<span class="number">9</span>]+),([<span class="number">0</span>-<span class="number">9</span>]+)-(.*).html(<span class="regexp">/?)+$ /</span>engine/print.php?news_page=$<span class="number">2</span>&newsid=$<span class="number">3</span>&seourl=$<span class="number">4</span>&seocat=$<span class="number">1</span> last;
rewrite ^<span class="regexp">/([^.]+)/</span>([<span class="number">0</span>-<span class="number">9</span>]+)-(.*).html(<span class="regexp">/?)+$ /i</span>ndex.php?newsid=$<span class="number">2</span>&seourl=$<span class="number">3</span>&seocat=$<span class="number">1</span> last;

rewrite ^<span class="regexp">/page,([0-9]+),([0-9]+),([0-9]+)-(.*).html(/</span>?)+$ /index.php?newsid=$<span class="number">3</span>&news_page=$<span class="number">1</span>&cstart=$<span class="number">2</span>&seourl=$<span class="number">4</span> last;
rewrite ^<span class="regexp">/page,([0-9]+),([0-9]+)-(.*).html(/</span>?)+$ /index.php?newsid=$<span class="number">2</span>&news_page=$<span class="number">1</span>&seourl=$<span class="number">3</span> last;
rewrite ^<span class="regexp">/print:page,([0-9]+),([0-9]+)-(.*).html(/</span>?)+$ /engine/print.php?news_page=$<span class="number">1</span>&newsid=$<span class="number">2</span>&seourl=$<span class="number">3</span> last;
rewrite ^<span class="regexp">/([0-9]+)-(.*).html(/</span>?)+$ /index.php?newsid=$<span class="number">1</span>&seourl=$<span class="number">2</span> last;

# For day
rewrite ^<span class="regexp">/([0-9]+)/</span>([<span class="number">0</span>-<span class="number">9</span>]+)/([<span class="number">0</span>-<span class="number">9</span>]+)(<span class="regexp">/?)+$ /i</span>ndex.php?year=$<span class="number">1</span>&month=$<span class="number">2</span>&day=$<span class="number">3</span> last;
rewrite ^<span class="regexp">/([0-9]+)/</span>([<span class="number">0</span>-<span class="number">9</span>]+)/([<span class="number">0</span>-<span class="number">9</span>]+)/page/([<span class="number">0</span>-<span class="number">9</span>]+)(<span class="regexp">/?)+$ /i</span>ndex.php?year=$<span class="number">1</span>&month=$<span class="number">2</span>&day=$<span class="number">3</span>&cstart=$<span class="number">4</span> last;
# For all months
rewrite ^<span class="regexp">/([0-9]+)/</span>([<span class="number">0</span>-<span class="number">9</span>]+)(<span class="regexp">/?)+$ /i</span>ndex.php?year=$<span class="number">1</span>&month=$<span class="number">2</span> last;
rewrite ^<span class="regexp">/([0-9]+)/</span>([<span class="number">0</span>-<span class="number">9</span>]+)/page/([<span class="number">0</span>-<span class="number">9</span>]+)(<span class="regexp">/?)+$ /i</span>ndex.php?year=$<span class="number">1</span>&month=$<span class="number">2</span>&cstart=$<span class="number">3</span> last;
# Output <span class="keyword">for</span> the entire year
rewrite ^<span class="regexp">/([0-9]+)(/</span>?)+$ /index.php?year=$<span class="number">1</span> last;
rewrite ^<span class="regexp">/([0-9]+)/</span>page/([<span class="number">0</span>-<span class="number">9</span>]+)(<span class="regexp">/?)+$ /i</span>ndex.php?year=$<span class="number">1</span>&cstart=$<span class="number">2</span> last;
# Output <span class="keyword">for</span> tags
rewrite ^<span class="regexp">/tags/</span>([^<span class="regexp">/]*)(/</span>?)+$ /index.php?<span class="keyword">do</span>=tags&tag=$<span class="number">1</span> last;
rewrite ^<span class="regexp">/tags/</span>([^<span class="regexp">/]*)/</span>page/([<span class="number">0</span>-<span class="number">9</span>]+)(<span class="regexp">/?)+$ /i</span>ndex.php?<span class="keyword">do</span>=tags&tag=$<span class="number">1</span>&cstart=$<span class="number">2</span> last;
# Output <span class="keyword">for</span> users
rewrite ^<span class="regexp">/user/</span>([^<span class="regexp">/]*)/</span>rss.xml$ /engine/rss.php?subaction=allnews&user=$<span class="number">1</span> last;
rewrite ^<span class="regexp">/user/</span>([^<span class="regexp">/]*)(/</span>?)+$ /index.php?subaction=userinfo&user=$<span class="number">1</span> last;
rewrite ^<span class="regexp">/user/</span>([^<span class="regexp">/]*)/</span>page/([<span class="number">0</span>-<span class="number">9</span>]+)(<span class="regexp">/?)+$ /i</span>ndex.php?subaction=userinfo&user=$<span class="number">1</span>&cstart=$<span class="number">2</span> last;
rewrite ^<span class="regexp">/user/</span>([^<span class="regexp">/]*)/</span>news(<span class="regexp">/?)+$ /i</span>ndex.php?subaction=allnews&user=$<span class="number">1</span> last;
rewrite ^<span class="regexp">/user/</span>([^<span class="regexp">/]*)/</span>news/page/([<span class="number">0</span>-<span class="number">9</span>]+)(<span class="regexp">/?)+$ /i</span>ndex.php?subaction=allnews&user=$<span class="number">1</span>&cstart=$<span class="number">2</span> last;
rewrite ^<span class="regexp">/user/</span>([^<span class="regexp">/]*)/</span>news/rss.xml(<span class="regexp">/?)+$ /</span>engine/rss.php?subaction=allnews&user=$<span class="number">1</span> last;
# Output <span class="keyword">for</span> last news
rewrite ^<span class="regexp">/lastnews/</span>(<span class="regexp">/?)+$ /i</span>ndex.php?<span class="keyword">do</span>=lastnews last;
rewrite ^<span class="regexp">/lastnews/</span>page/([<span class="number">0</span>-<span class="number">9</span>]+)(<span class="regexp">/?)+$ /i</span>ndex.php?<span class="keyword">do</span>=lastnews&cstart=$<span class="number">1</span> last;
# Output <span class="keyword">for</span> catalog
rewrite ^<span class="regexp">/catalog/</span>([^<span class="regexp">/]*)/</span>rss.xml$ /engine/rss.php?catalog=$<span class="number">1</span> last;
rewrite ^<span class="regexp">/catalog/</span>([^<span class="regexp">/]*)(/</span>?)+$ /index.php?catalog=$<span class="number">1</span> last;
rewrite ^<span class="regexp">/catalog/</span>([^<span class="regexp">/]*)/</span>page/([<span class="number">0</span>-<span class="number">9</span>]+)(<span class="regexp">/?)+$ /i</span>ndex.php?catalog=$<span class="number">1</span>&cstart=$<span class="number">2</span> last;
# Output <span class="keyword">for</span> <span class="keyword">new</span> posts
rewrite ^<span class="regexp">/newposts(/</span>?)+$ /index.php?subaction=newposts last;
rewrite ^<span class="regexp">/newposts/</span>page/([<span class="number">0</span>-<span class="number">9</span>]+)(<span class="regexp">/?)+$ /i</span>ndex.php?subaction=newposts&cstart=$<span class="number">1</span> last;
# Output <span class="keyword">for</span> favorites news
rewrite ^<span class="regexp">/favorites(/</span>?)+$ /index.php?<span class="keyword">do</span>=favorites last;
rewrite ^<span class="regexp">/favorites/</span>page/([<span class="number">0</span>-<span class="number">9</span>]+)(<span class="regexp">/?)+$ /i</span>ndex.php?<span class="keyword">do</span>=favorites&cstart=$<span class="number">1</span> last;

rewrite ^<span class="regexp">/rules.html$ /i</span>ndex.php?<span class="keyword">do</span>=rules last;
rewrite ^<span class="regexp">/statistics.html$ /i</span>ndex.php?<span class="keyword">do</span>=stats last;
rewrite ^<span class="regexp">/addnews.html$ /i</span>ndex.php?<span class="keyword">do</span>=addnews last;
rewrite ^<span class="regexp">/rss.xml$ /</span>engine/rss.php last;
rewrite ^<span class="regexp">/sitemap.xml$ /</span>uploads/sitemap.xml last;

<span class="keyword">if</span> (!-d $request_filename) {
    rewrite ^<span class="regexp">/([^.]+)/</span>page/([<span class="number">0</span>-<span class="number">9</span>]+)(<span class="regexp">/?)+$ /i</span>ndex.php?<span class="keyword">do</span>=cat&category=$<span class="number">1</span>&cstart=$<span class="number">2</span> last;
    rewrite ^<span class="regexp">/([^.]+)/</span>?$ /index.php?<span class="keyword">do</span>=cat&category=$<span class="number">1</span> last;
}

<span class="keyword">if</span> (!-f $request_filename) {
    rewrite ^<span class="regexp">/([^<]+)/</span>rss.xml$ /engine/rss.php?<span class="keyword">do</span>=cat&category=$<span class="number">1</span> last;
    rewrite ^<span class="regexp">/page,([0-9]+),([^/</span>]+).html$ /index.php?<span class="keyword">do</span>=static&page=$<span class="number">2</span>&news_page=$<span class="number">1</span> last;
    rewrite ^<span class="regexp">/print:([^/</span>]+).html$ /engine/print.php?<span class="keyword">do</span>=static&page=$<span class="number">1</span> last;
}

<span class="keyword">if</span> (!-f $request_filename) {
    rewrite ^<span class="regexp">/([^/</span>]+).html$ /index.php?<span class="keyword">do</span>=static&page=$<span class="number">1</span> last;
}

请将上述代码存成 .conf 文件 ( linux 系统该文件保存在 /usr/local/nginx/conf ),并在网站设置里面加载

订阅评论
提醒
guest的头像

0 评论
内联反馈
查看所有评论
0
希望看到您的想法,请您发表评论x