国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > Nginx > 正文

Nginx rewrite重寫規則實例和注意事項

2024-08-30 12:27:30
字體:
來源:轉載
供稿:網友

rewrite 重寫規則可以讓網站URL看起來非常簡介,對搜索引擎友好,有利于給網站用戶帶來記憶上的方便,給網站帶來更多流量。

因此編寫網站rewrite規則很重要。Nginx的rewrite規則非常強大,下面是樓主實際使用過的一些配置最為例子放出來給大家參考。

注意寫到location里面,否則$request_filename找不對路徑,無效。

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;
}

下面是應用于Discuz論壇的Nginx rewrite規則:
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;

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 武夷山市| 郑州市| 台东市| 沛县| 宿州市| 名山县| 乌鲁木齐县| 通许县| 青岛市| 微博| 赣州市| 延吉市| 务川| 台中县| 靖西县| 思南县| 乌鲁木齐市| 库伦旗| 宽城| 福清市| 神池县| 澄城县| 城口县| 稻城县| 如东县| 洛隆县| 沽源县| 柳州市| 翁牛特旗| 清水县| 阜新市| 双牌县| 天全县| 石城县| 大余县| 赤峰市| 沙雅县| 方山县| 麻阳| 修文县| 宜君县|