“配置MW:短链接”的版本间差异
| 无编辑摘要 | |||
| 第1行: | 第1行: | ||
| [[MediaWiki]] | [[category:MediaWiki]] | ||
| 短URL或URL重写会隐藏页面地址中的php文件扩展名。格式如:<code>http://wiki.eijux.com/%E9%A6%96%E9%A1%B5</code>、<code>http://wiki.eijux.com/wiki/%E9%A6%96%E9%A1%B5</code><br/> | 短URL或URL重写会隐藏页面地址中的php文件扩展名。格式如:<code>http://wiki.eijux.com/%E9%A6%96%E9%A1%B5</code>、<code>http://wiki.eijux.com/wiki/%E9%A6%96%E9%A1%B5</code><br/> | ||
2020年9月13日 (日) 19:17的版本
短URL或URL重写会隐藏页面地址中的php文件扩展名。格式如:http://wiki.eijux.com/%E9%A6%96%E9%A1%B5、http://wiki.eijux.com/wiki/%E9%A6%96%E9%A1%B5
MediwWiki默认的文章链接格式为如:http://wiki.eijux.com/index.php?title=%E9%A6%96%E9%A1%B5
默认文章操作链接格式如:http://wiki.eijux.com/index.php?title=%E9%A6%96%E9%A1%B5&action=edit
(短链接的修改参见Manual:Short URL页面,对于MediaWiki设置Short URL的注意事项,以及针对不同服务器环境的配置都十分具体。)
配置步骤
(此次采用的设置参见Manual:Short URL/Page title - nginx, Root Access, PHP as a CGI module)
LocalSettings.php设置
如下:
# Short URL $wgArticlePath = "/$1"; $wgUsePathInfo = true; $wgScriptExtension = ".php";
nginx configuration设置
修改站点的nginx配置文件,使用BTPabel安装的LNMP环境,可在面板操作“网站->wiki.eijux.com设置->配置文件”进行设置。
(宝塔中站点的nginx配置文件(如"wiki.eijux.com.conf"),位于"/www/server/panel/vhost/nginx")
添加:
    location / {
        try_files $uri $uri/ @rewrite;
    }
    location @rewrite {
        rewrite ^/(.*)$ /index.php;
    }
就可完成短链接的转换。另:
    # 限制访问.ht文件
    location ~ \.ht {
        deny all;
    }
    # 限制对maintenance该路径的访问,返回403
    location ^~ /maintenance/ {
        return 403;
    }
    # 以下配置允许运行.php的程序
    # 关于fastcgi的配置,参见"/www/server/nginx/conf"中的"enable-php-73.conf"
    # ("fastcgi_params"和"fastcgi.conf"均位于"/www/server/nginx/conf"中)
    location ~ \.php$ {
        include /www/server/nginx/conf/fastcgi_params;
        fastcgi_pass  unix:/tmp/php-cgi-73.sock;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME	$document_root$fastcgi_script_name;
        try_files $uri @rewrite;
    }
重载nginx配置
使用BTPanel或命令进行nginx的重载配置。
完成配置。长链接http://wiki.eijux.com/index.php?title=%E9%A6%96%E9%A1%B5、短链接http://wiki.eijux.com/%E9%A6%96%E9%A1%B5均可正常访问。
关于$wgActionPaths
设置以上$wgArticlePath等设置之后,页面的链接变为了短链接(如:http://wiki.eijux.com/%E9%A6%96%E9%A1%B5),但是页面的编辑、移动、删除、历史等页面,仍然是长链接页面(如:http://wiki.eijux.com/%E9%A6%96%E9%A1%B5?action=edit&veswitched=1),若要使操作页面也应用短链接,则应该设置$wgActionPaths。(参见Manual:$wgActionPaths)
如,设置Action在页面之后:
#  Short URL of Action
$actions = array( 'edit', 'watch', 'unwatch', 'delete','revert', 'rollback', 'protect', 'unprotect', 'markpatrolled', 'render', 'submit', 'history', 'purge', 'info' );
foreach ( $actions as $action ) {
	$wgActionPaths[$action] = "/$1/$action";
}
$wgActionPaths['view'] = "/$1";
$wgArticlePath = $wgActionPaths['view'];
则页面编辑链接为http://wiki.eijux.com/%E9%A6%96%E9%A1%B5/edit。
- 但是:
- 使用$wgActionPaths设置,则不能创建某些与$actions中定义的操作词相关的页面,如:创建名为“首页/edit”(action后置)、“edit/首页”(action后置)、“首页/history”的页面时,会跳转到“首页”相关的操作页面。所以不建议使用,或者修改$actions的操作词为不常用词(可能需要修改页面代码?)。
 
- 使用
关于example.com/Page_title
使用域的根目录作为wiki目录,并使url如下所示:example.com/Page_title,但并不是官方建议的方式。因为它可能会导致与其他文件和目录冲突。如:图像位于/images/目录中,则无法访问wiki中名为“images”的页面;并且无法创建控制搜索引擎索引页面的robots.txt.txt文件。(参见Manual:Wiki in site root directory)
- 可能的bug如:task T34621、task T40048。
但同时这种方式在Gamepedia运行良好。
目前并没有遇到、涉及上述问题,私人小站也不担心链接变动的SEO影响(Cool URIs don't change)。