wangsisi 发表于 2011-7-5 17:55:25

mediawiki页面伪静态配置调试

简单mediawiki页面伪静态配置:

最简单的莫过于把LocalSettings.php中添加一句$wgUsePathInfo = true;这样默认的连接是”http://wiki.clin003.com/index.php/首页”,这种链接用的也很普遍的,并且还没有发现什么问题。

自定义mediawiki页面伪静态配置:

链接样子“http://wiki.clin003.com/wiki/%E9%A6%96%E9%A1%B5”(这是首页的链接)。

配置方法为:

首先建立一个.htaccess文件,内容为:

##安装路径在子目录!!

RewriteEngine on
RewriteRule index.htm /e/index.php ##这里需要在根目录建一个index.htm的空文件
RewriteRule wiki/(.+) /e/index.php/$1 ##主要这里解决的搜索没结果问题,和下边的重复有点混乱ing
RewriteRule wiki/(.+) /e/index.php?title=$1

推荐使用的.htaccess文件内容(来自官方文档):

PS:使用这个你就不用在根目录建index.htm空文件啦

##http://www.mediawiki.org/wiki/Manual:Short_URL/wiki/Page_title_–_no_root_access

Options FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^wiki/(.*)$ e/index.php?title=$1
RewriteRule ^wiki/*$ wiki/
RewriteRule ^/*$ wiki/

然后编辑LocalSettings.php

$wgScriptPath = "/e";         # Path to the actual files (right part of first rewrite rule). Should already be there
##mediawiki安装的(相对根目录)路径,若在根目录安装的就留空吧
##推荐安装在子目录的目的是方便对搜索引擎蜘蛛的爬行控制
$wgArticlePath = "/wiki/$1";# Virtual path (left part of first rewrite rule). MUST be DIFFERENT from the path above!
##虚拟路径,这个可以自定义,但不可以与安装目录重名(重名的话就没多大意义啦,直接使用第一种办法)。
想了解更多的mediawiki伪静态配置办法可以访问:http://www.mediawiki.org/wiki/Manual:Short_URL#Defaults

控制搜索引擎蜘蛛访问:
再根目录放置robots.txt内容为
User-agent: *
Disallow: /e/
Disallow: /wiki/Special:Search
Disallow: /wiki/Special:Random
这样就禁止所有搜索引擎蜘蛛爬行/e/目录(mediawiki程序安装目录),搜索结果页面,随机页面。
PS:本来以为自己找到解决这个搜索问题啦,可发现维基百科提供的.htaccess跟实用,所以就推荐官方的那个啦,我写的那个.htaccess就不推荐使用啦o(∩_∩)o...哈哈

考虑服务器负载的自定义mediawiki页面伪静态配置:
from:http://easun.org/archives/wikimedia_wiki_url_short.html
1.改名字:

    mv index.php show
    mv redirect.php redirect

2.修改.htaccess 规则

    <Files ~ (show|redirect)>
    ForceType application/x-httpd-php
    </Files>
    DirectoryIndex show

3.修改修改LocalSettings.php 中 $wgScript,$wgRedirectScript,$wgArticlePath 的值

    $wgScript = "$wgScriptPath/show";
    $wgRedirectScript = "$wgScriptPath/redirect";
    $wgArticlePath = "$wgScript/$1";

因为没有使用 mod_rewrite ,网站的负荷下降,效率当然提升了:)
页: [1]
查看完整版本: mediawiki页面伪静态配置调试

BlueHost美国主机优惠码