从MediaWiki操作URL中删除index.php [英] Removing index.php from MediaWiki action URLs

查看:779
本文介绍了从MediaWiki操作URL中删除index.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,因此有据可查的如何隐藏index.php ?title =网址中的位,但我想对所有动作类型链接隐藏它,类似于扩展 ShortUrls 应该可以工作(它不在我的网站上,并且我不知道如何解决).我没有访问.htaccess的权限,并且正在考虑通过在common.js页面中添加一些javascript或修改ShortLinks扩展名来进行此操作,但是这些钩子上的文档不是很好,我尝试过的东西也不是帮助.

OK so its fairly well documented how to hide the index.php?title= bit from urls, but what I would like is to hide it for all the action type links, similar to how the extension ShortUrls is supposed to work (It doesn't on my site and I don't know how to fix it). I don't have access to .htaccess and was thinking of doing it by adding some javascript to the common.js page, or by modifying the ShortLinks extension but the documentation on those hooks isn't very good and anything I tried wasn't helping.

推荐答案

基本上,您需要将条目添加到

Basically, you need to add an entry to $wgActionPaths for each action that you want to use a short URL for.

例如,如果您希望页面Foobar的普通视图URL为/wiki/Foobar,而编辑和历史URL为例如/wiki/edit/Foobar/wiki/history/Foobar,则可以添加以下内容行到您的LocalSettings.php:

For example, if you want the normal view URL of the page Foobar to be /wiki/Foobar, and the edit and history URLs to be, say, /wiki/edit/Foobar and /wiki/history/Foobar, you'd add the following lines to your LocalSettings.php:

$wgArticlePath = '/wiki/$1';
$wgActionPaths['edit'] = '/wiki/edit/$1';
$wgActionPaths['history'] = '/wiki/history/$1';

当然,您还需要配置Web服务器,以将对这些短URL的所有请求改写回MediaWiki可以理解的内容,例如在Apache上使用mod_rewrite.我上面链接到的文档页面上有一些有用的示例.

Of course, you'll also need to configure your web server to rewrite any requests for those short URLs back into something MediaWiki will understand, e.g. using mod_rewrite on Apache. The documentation page I linked to above has some helpful examples.

通常,您可以使用 GetLocalURL 以任意方式转换MediaWiki生成的URL.或 GetLocalURL :: Internal 挂钩. (这两个钩子之间的主要区别是,还为跨维基URL调用了GetLocalURL钩子.)这些钩子是从

More generally, you can transform MediaWiki-generated URLs in arbitrary ways using a GetLocalURL or GetLocalURL::Internal hook. (The main difference between the two hooks is that the GetLocalURL hook is also called for interwiki URLs.) These hooks are called from the Title::GetLocalURL(), which you may want to take a look at to see how they work.

例如,这是将diff URL转换为/wiki/diff/revA/revB/Page_name格式的方法:

For example, here's how you could transform diff URLs into the format /wiki/diff/revA/revB/Page_name:

function prettyDiffURLs( $title, &$url, $query ) {
    if ( preg_match( '/^diff=(\w+)&oldid=(\w+)$/', $query, $matches ) ) {
        $dbkey = wfUrlencode( $title->getPrefixedDBkey() );
        $url = "/wiki/diff/$matches[1]/$matches[2]/$dbkey";
    }
    return true;
}
$wgHooks['GetLocalURL::Internal'][] = 'prettyDiffURLs';

(警告:我相信此代码应该可以工作,但我尚未对其进行测试!)

(Warning: I believe this code should work, but I have not tested it!)

这篇关于从MediaWiki操作URL中删除index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆