MediaWiki主页URL配置:去除/w/Main_Page,仅保留域名
配置MediaWiki主页URL为纯域名
我刚接触MediaWiki,已按照ShortURL指南完成文章路径配置。现需设置主页URL仅显示域名help.pearldentalsoftware.com,而非带有/w/Main_Page的路径。以下是当前的配置代码:
当前LocalSettings.php配置
$wgMetaNamespace = "Pearl_Dental_Software_Wiki"; ## The URL base path to the directory containing the wiki; ## defaults for all runtime URL paths are based off of this. ## For more information on customizing the URLs ## (like /w/index.php/Page_title to /wiki/Page_title) please see: ## https://www.mediawiki.org/wiki/Manual:Short_URL $wgScriptPath = ""; $wgScript = "{$wgScriptPath}/"; $wgArticlePath = "/w/$1"; $wgUsePathInfo = true; ## The protocol and server name to use in fully-qualified URLs $wgServer = "https://help.pearldentalsoftware.com"; ## The URL path to static resources (images, scripts, etc.) $wgResourceBasePath = $wgScriptPath;
当前.htaccess配置
RewriteEngine On RewriteRule ^/?w(/.*)?$ %{DOCUMENT_ROOT}/ [L] RewriteCond %{HTTP_USER_AGENT} !^(VisualEditor) RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d RewriteRule ^/?images/thumb/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&width=$2 [L,QSA,B] RewriteCond %{HTTP_USER_AGENT} !^(VisualEditor) RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d RewriteRule ^/?images/thumb/archive/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&width=$2&archived=1 [L,QSA,B]
解决方案
要实现主页仅显示纯域名,需同时调整LocalSettings.php和.htaccess的配置:
1. 修改LocalSettings.php
添加以下配置项,让MediaWiki识别根路径对应主页:
# 指定主页标题,需与实际主页名称一致 $wgMainPageTitle = "Main_Page"; # 开启根路径自动跳转至主页 $wgRedirectRootToMainPage = true;
现有路径配置(如$wgArticlePath = "/w/$1")可保留,不影响文章的ShortURL规则。
2. 更新.htaccess
添加根路径转发规则,同时保留原有图片缩略图处理逻辑,修改后的代码如下:
RewriteEngine On # 将根路径请求转发到MediaWiki入口文件,加载主页 RewriteRule ^$ %{DOCUMENT_ROOT}/index.php [L] # 保留原/w路径的文章处理规则 RewriteRule ^/?w(/.*)?$ %{DOCUMENT_ROOT}/index.php$1 [L] # 图片缩略图处理规则(原规则保留) RewriteCond %{HTTP_USER_AGENT} !^(VisualEditor) RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d RewriteRule ^/?images/thumb/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&width=$2 [L,QSA,B] RewriteCond %{HTTP_USER_AGENT} !^(VisualEditor) RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d RewriteRule ^/?images/thumb/archive/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&width=$2&archived=1 [L,QSA,B]
说明
$wgRedirectRootToMainPage = true配合.htaccess规则,可直接处理根路径请求,避免额外重定向。- 确保服务器已启用mod_rewrite模块,且.htaccess文件权限正确,能被Apache读取。
内容的提问来源于stack exchange,提问作者Taylor Southorn
相关产品推荐
相关产品推荐

