qienkuen發表於30 Jun 2007 01:59 am

为Mediawiki做Pretty URL

Current Mood:Esctatic emoticon Esctatic

刚才用了一个小时左右折腾Mediawiki“洁净的URL”,终于为“教育中文翻译·Wiki”做好了漂亮、整洁的URL。此次折腾,参考了网络上的资料,受到启发,自己做了小的改动:

天下维客有关“洁净URL”的页面中提到了好多种方法,我先试了多种不使用mod_rewrite方法的一种,获得成功,效果是“www.edu2do.com/eduwiki/wiki/首页”的样子。但我不喜欢多出一个/wiki来,所以打算尝试新的方法。

然后找到了这篇文章,根据这里的提示,我基本完成了URL的美化。但问题是:在注册和登陆时,原URL未被正确重置。从而导致我眼看着“用户登陆”,点击并填入信息后,就是不能注册和登陆。于是我开始一行行地分析RewriteRules。

然后我找到一行错误的东西:

RewriteRule ^(.*)$ /wiki/index.php$1 [L]

我把它改成了这样:

RewriteRule ^(.*)$ /wiki/index.php?title=$1 [L,QSA]

请注意,差别就在于“?title=”这里,其它地方都没问题。就是这里让URL未被正确重置。改过之后,就可以正常注册、登陆无误了,并且现在没有了中间多套一层的“/wiki”,看上去舒服些了。--其实我发现呀,这东西万变不离其宗!

分享下.htaccess文件和LocalSettings.php中一些设置(以下abc是指安装mediawiki的目录):
.htaccess RewriteRules如下:

RewriteEngine On

RewriteBase /abc

RewriteCond %{REQUEST_URI} !^/abc/$

RewriteCond %{REQUEST_URI} !^/abc/(stylesheets|images|skins)/

RewriteCond %{REQUEST_URI} !^/abc/(redirect|texvc|index).php

RewriteCond %{REQUEST_URI} !^/abc/error/(40(1|3|4)|500).html

RewriteCond %{REQUEST_URI} !^/abc/favicon.ico

RewriteCond %{REQUEST_URI} !^/abc/robots.txt

RewriteCond %{QUERY_STRING} ^$ [OR] %{REQUEST_URI} ^/abc/Special:Search

RewriteRule ^(.*)$ /abc/index.php?title=$1 [L,QSA]

LocalSettings.php我是学习来的,要改的地方很少:

$wgSitename = “教育中文翻译·Wiki”;

$wgScriptPath = “/abc”;

$wgScript = “$wgScriptPath/abc”;

$wgRedirectScript = “$wgScriptPath/redirect.php”;

$wgArticlePath = “$wgScriptPath/$1″;

##$wgArticlePath = “$wgScript?title=$1″;

update:刚刚发现这美化后的URL影响了上传文件,我找到原因再来分享一次吧!

One Response to “为Mediawiki做Pretty URL”

  1. on 02 Jul 2007 at 1:03 pm 1.Angelived said …

    你现在比我能折腾,哈哈

Trackback(引用通告) | Subscribe Comments of this post

Leave a Reply