MediaWiki 伪静态静态化

MediaWiki 伪静态静态化

官方的Nginx伪静态设置
https://www.mediawiki.org/wiki/Manual:Short_URL/Nginx

估计你们也难搞,建议采用宝塔面板,网站配置里面的静态化规则:

laravel5的规则

location / {  
    try_files $uri $uri/ /index.php$is_args$query_string;  
}  

MVC规则

location /{
    if (!-e $request_filename) {
       rewrite  ^(.*)$  /index.php/$1  last;
       break;
    }
}

MediaWiki静态化

宝塔面板 + Nginx
1、vhost上配置重定向,准确路径为/www/server/panel/vhost/nginx找到对应的网站文件,如www.iec.wiki.conf

location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
        try_files $uri /index.php;
        expires max;
        log_not_found off;
    }

    location = /_.gif {
        expires max;
        empty_gif;
    }

    location ^~ /cache/ {
        deny all;
    }

    location /dumps {
        root /var/www/mediawiki/local;
        autoindex on;
    }
  location ~ /\.ht {
    deny all;
  }
      location / {
        try_files $uri $uri/ @rewrite;
    }

    location @rewrite {
            rewrite ^/([^?]*)(?:\?(.*))? /index.php?title=$1&$2 last;
    }


#一键申请SSL证书验证目录相关设置
location ~ \.well-known{
    allow all;
}

 location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
    try_files $uri /index.php;
    expires max;
    log_not_found off;
}

location = /_.gif {
    expires max;
    empty_gif;
}

location ^~ /cache/ {
    deny all;
}

location /dumps {
    root /var/www/mediawiki/local;
    autoindex on;
}
location ~ /\.ht {
deny all;
}
  location / {
    try_files $uri $uri/ @rewrite;
}

location @rewrite {
rewrite ^/([^?]*)(?:\?(.*))? /index.php?title=$1&$2 last;
  
}   









—————————————————————————————————-
Rewrite.png

2,

代码

if ($server_port !~ 443){

rewrite ^(/.*)$ https://$host$1 permanent;

}

修改为

    #301-START
        if ($host ~ '^emc.wiki'){
r            eturn 301 https://www.emc.wiki$request_uri;
        }
    #301-END

3、配置文件localsettings.php添加如下代码

# 静态化
$wgScriptPath = "";
$wgArticlePath = "/wiki/$1";
$wgVariantArticlePath = "/$2/$1";
$wgUsePathInfo  = true;