Nginx下配置可用的Discuz! x3 URL Rewrite 伪静态

Nginx下配置discuz! x3 伪静态,可以按如下三个步骤来实现,本人亲测可用:

步骤1,在nginx配置文件中,添加:

复制代码 代码示例:

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;
if (!-e $request_filename) {
    return 404;
}

步骤2,登录discuz! x3的后台管理,打开SEO设置界面,勾选URL 静态化里边的复选框。
步骤3,重启nginx,使伪静态配置生效:

service nginx restart

Zen Cart嵌套目录的Nginx Rewrite规则

Zen Cart V1.5.1,Ultimate SEO 2.212,nginx/1.4.2下测试通过

完整规则如下

    # if the requested file exists, return it immediately
    if (-f $request_filename) {
        break;
    }
    #For Ultimate SEO URLs
    rewrite ^/(.*)-p-([0-9]+).html$ /index.php?main_page=product_info&products_id=$2&$args last;
    rewrite ^/(.*)-c-([0-9]+)_([0-9]+)/$ /index.php?main_page=index&cPath=$2_$3&$args last;
    rewrite ^/(.*)-c-([0-9]+)/$ /index.php?main_page=index&cPath=$2&$args last;
    rewrite ^/(.*)-m-([0-9]+).html$ /index.php?main_page=index&manufacturers_id=$2&$args last;
    rewrite ^/(.*)-pi-([0-9]+).html$ /index.php?main_page=popup_image&pID=$2&$args last;
    rewrite ^/(.*)-pr-([0-9]+).html$ /index.php?main_page=product_reviews&products_id=$2&$args last;
    rewrite ^/(.*)-pri-([0-9]+).html$ /index.php?main_page=product_reviews_info&products_id=$2&$args last;

# For eazy pages
    rewrite ^/(.*)-ezp-([0-9]+).html$ /index.php?main_page=page&id=$2&$args last;

# For Open Operations Info Manager
    rewrite ^/(.*)-i-([0-9]+).html$ /index.php?main_page=info_manager&pages_id=$2&$args last;

# For dreamscape's News & Articles Manager
rewrite "^news/?" /index.php?main_page=news&% last;
rewrite "^news/rss.xml" /index.php?main_page=news_rss&% last;
rewrite "^news/archive/?" /index.php?main_page=news_archive&% last;
rewrite "^news/([0-9]{4})-([0-9]{2})-([0-9]{2}).html" /index.php?main_page=news&date=$1-$2-$3&% last;
rewrite "^news/archive/([0-9]{4})-([0-9]{2}).html" /index.php?main_page=news_archive&date=$1-$2&% last;
rewrite "^news/(.*)-a-([0-9]+)-comments.html" /index.php?main_page=news_comments&article_id=$2&% last;
rewrite "^news/(.*)-a-([0-9]+).html" /index.php?main_page=news_article&article_id=$2&% last;
 
# All other pages
# Don't rewrite real files or directories
rewrite "^(.*).html" /index.php?main_page=$1&% last;

请注意这条Rewrite规则,这就是嵌套目录规则

rewrite ^/(.*)-c-([0-9]+)_([0-9]+)/$ /index.php?main_page=index&cPath=$2_$3&$args last;

附录,Wordpress安装在子目录时的Rewrite 规则

    location / {

    rewrite ^/blog/wp-admin$ /blog/wp-admin/ permanent;

    if (-f $request_filename/index.html){
        rewrite ^/blog/(.*) /blog/$1/index.html break;
    }

    if (-f $request_filename/index.php){
        rewrite ^/blog/(.*) /blog/$1/index.php;
    }

    if (!-f $request_filename){
        rewrite ^/blog/(.*) /blog/index.php;
    }
}