discuz論壇的靜態化之路(linux,nginx版)

靜態化,縮短了url的長度,也便於搜索引擎收錄。
1、在論壇代碼目錄下新建文件“.htaccess”

vim /usr/share/nginx/html/bbs/.htaccess //bbs下放置着我的論壇代碼

2、在文件“.htaccess”裏添加僞靜態規則

# nginx rewrite rule
rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
rewrite ^([^\.]*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last;
rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last;
rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last;
# end nginx rewrite rule

3、配置到nginx文件

vim /etc/nginx/nginx.conf
    server {
        listen       80;
        listen       localhost;
        server_name  _;
        root         /usr/share/nginx/html/bbs;
        include /usr/share/nginx/html/bbs/.htaccess; #引入文件“.htaccess”

        location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index  index.php;
            include fastcgi.conf;
        }
    }

4、重啓服務

/usr/sbin/nginx -s reload
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章