升级到 Mediawiki 1.24.2 后漂亮的 URL 不起作用

Pretty URLs aren't working after upgrade to Mediawiki 1.24.2

所以我要将我的一个 Mediawiki 站点移动到一个新服务器上。版本 1.20.3 在旧服务器 运行 Ubuntu 12.04 上运行良好。但是,当我将所有内容复制到我的新服务器 运行 Ubuntu 14.04 时,它没有。因此,在弄乱了一段时间后,我决定同时从 1.20.3 升级到 1.24.2 可能更容易。

我得到了 1.24.2。从 Mediawiki 下载站点。解压缩它。 运行 maintenance/upgrade.php 并将我所有的扩展、图像、上传、皮肤、徽标和 LocalSettings.php 文件从 1.20.3 复制到 1.24.2。只要我使用 http://wikis.controltheorypro.com/index.php?title=Main_Page but does not when I use http://wikis.controltheorypro.com/Main_Page or http://wikis.controltheorypro.com/ (which redirects to http://wikis.controltheorypro.com/Main_Page).

,1.24.2 站点就可以正常工作

旧服务器上的 1.20.3 重定向工作正常。 LocalSetting.php 或 DB 中的某些内容仍在告诉 Mediawiki 使用漂亮的 URLs 因为我主页上的所有 URLs 都缺少 index.php?title= URL.

的一部分

我是一个相当称职的 PHP 和服务器人员,但这是一个旧站点,我只有在移动服务器时才真正处理过它。这是我几年前投入大量精力的网站。我现在已经杀了它,但它似乎从学生那里得到了很多流量,所以我让它活着。

我已经通过 Google 和 Mediawiki 站点尝试了几种解决方案。

此时我的 .htaccess 是一团糟,但这里是:

#RewriteEngine on

#RewriteCond %{HTTP_HOST} ^controltheorypro.com$ [OR]
#RewriteCond %{HTTP_HOST} ^www.controltheorypro.com$
#RewriteRule ^/?$ "http\:\/\/wikis\.controltheorypro\.com" [R=301,L]

<IfModule mod_rewrite.c>
# Turn on mod_rewrite
RewriteEngine On

# Virtual path to index.php
RewriteRule ^/?(/.*)?$ %{DOCUMENT_ROOT}/index.php [L]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/index.php [L]
RewriteRule ^/*$ %{DOCUMENT_ROOT}/index.php [L]

# If you are converting from a static site to a wiki,
# you'll want to make redirections to the new article.
#RewriteRule ^old-file.html$ http://www.example.com/New_Article [R=permanent,L]

# This hack lets you essentially gets rid of the redirection
# to "Main Page".  Conversely, if you go to http://www.example.com/Main_Page,
# it sends an permanent external redirection to http://www.example.com/.
RewriteRule ^Main_Page$ http://wikis.controltheorypro.com/ [R=permanent,L]
RewriteRule ^$ /var/www/html/CTP/mediawiki-1.24.2/index.php?title=Main_Page&redirect=no [QSA,L]

RewriteRule ^/new/rss http://wikis.controltheorypro.com/index.php?title=Special:NewPages&feed=rss [QSA,L]
RewriteRule ^/do/([a-z]*)/(.*)$ /var/www/html/CTP/mediawiki-1.24.2/index.php?action=&title= [QSA,L]

# Finally, if we've gotten this far, process it as if it's an article,
# UNLESS it's a physical file/directory/symlink.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /var/www/html/CTP/mediawiki-1.24.2/index.php?title= [QSA,L]
</IfModule>

LocalSettings.php:

<?php
# This file was automatically generated by the MediaWiki 1.20.3
# installer. If you make manual changes, please keep track in case you
# need to recreate them later.
#
# See includes/DefaultSettings.php for all configurable settings
# and their default values, but don't forget to make changes in _this_
# file, not there.
#
# Further documentation for configuration settings may be found at:
# http://www.mediawiki.org/wiki/Manual:Configuration_settings

# Protect against web entry
if ( !defined( 'MEDIAWIKI' ) ) {
        exit;
}

## Uncomment this to disable output compression
# $wgDisableOutputCompression = true;

$wgSitename      = "ControlTheoryPro.com";

## 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:
## http://www.mediawiki.org/wiki/Manual:Short_URL
$wgScriptPath       = "";
$wgScriptExtension  = ".php";

## Added by me to enable pretty permalinks
$wgArticlePath = "$wgScriptPath/";
$wgUsePathInfo = true;

## The protocol and server name to use in fully-qualified URLs
$wgServer           = "http://wikis.controltheorypro.com";

## The relative URL path to the skins directory
$wgStylePath        = $wgScriptPath . "/skins";

## The relative URL path to the logo.  Make sure you change this from the default,
## or else you'll overwrite your logo when you upgrade!
$wgLogo             = $wgServer . "/logo.gif"; // "/wiki_symbol_default_size.png"; // "$wgStylePath/common/images/wiki.png";

## UPO means: this is also a user preference option

$wgEnableEmail      = true;
$wgEnableUserEmail  = true; # UPO

$wgEmergencyContact = "admin@controltheorypro.com";
$wgPasswordSender   = "admin@controltheorypro.com";

$wgEnotifUserTalk      = false; # UPO
$wgEnotifWatchlist     = false; # UPO
$wgEmailAuthentication = true;

## Database settings
....

# MySQL specific settings
$wgDBprefix         = "";

# MySQL table options to use during installation or update
$wgDBTableOptions   = "ENGINE=InnoDB, DEFAULT CHARSET=binary";

# Experimental charset support for MySQL 5.0.
$wgDBmysql5 = false;

## Shared memory settings
$wgMainCacheType    = CACHE_MEMCACHED;
$wgMemCachedServers = array( '127.0.0.1:11211' );

## To enable image uploads, make sure the 'images' directory
## is writable, then set this to true:
$wgEnableUploads  = true;
#$wgUseImageMagick = true;
#$wgImageMagickConvertCommand = "/usr/bin/convert";

# InstantCommons allows wiki to use images from http://commons.wikimedia.org
$wgUseInstantCommons  = true;

## If you use ImageMagick (or any other shell command) on a
## Linux server, this will need to be set to the name of an
## available UTF-8 locale
$wgShellLocale = "en_US.utf8";

## If you want to use image uploads under safe mode,
## create the directories images/archive, images/thumb and
## images/temp, and make them all writable. Then uncomment
## this, if it's not already uncommented:
#$wgHashedUploadDirectory = false;

## Set $wgCacheDirectory to a writable directory on the web server
## to make your wiki go slightly faster. The directory should not
## be publically accessible from the web.
#$wgCacheDirectory = "$IP/cache";

# Site language code, should be one of the list in ./languages/Names.php
$wgLanguageCode = "en";

$wgSecretKey = ...;

# Site upgrade key. Must be set to a string (default provided) to turn on the
# web installer while LocalSettings.php is in place
$wgUpgradeKey = ...;

## Default skin: you can change the default skin. Use the internal symbolic
## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook', 'vector':
$wgDefaultSkin = "gumaxdd"; // "vector";

## For attaching licensing metadata to pages, and displaying an
## appropriate copyright notice / icon. GNU Free Documentation
## License and Creative Commons licenses are supported so far.
$wgRightsPage = ""; # Set to the title of a wiki page that describes your license/copyright
$wgRightsUrl  = "http://creativecommons.org/licenses/by-nc-sa/3.0/";
$wgRightsText = "Creative Commons Attribution Non-Commercial Share Alike";
$wgRightsIcon = "{$wgStylePath}/common/images/cc-by-nc-sa.png";

# Path to the GNU diff3 utility. Used for conflict resolution.
$wgDiff3 = "/usr/bin/diff3";            // Manually added - GTS 04/11/13

# Query string length limit for ResourceLoader. You should only set this if
# your web server has a query string length limit (then set it to that limit),
# or if you have suhosin.get.max_value_length set in php.ini (then set it to
# that value)
$wgResourceLoaderMaxQueryLength = -1;

# The following permissions were set based on your choice in the installer
$wgGroupPermissions['*']['edit'] = false;

# Enabled Extensions. Most extensions are enabled by including the base extension file here
# but check specific extension documentation for more details
# The following extensions were automatically enabled:
require_once( "$IP/extensions/ConfirmEdit/ConfirmEdit.php" );
require_once( "$IP/extensions/Gadgets/Gadgets.php" );
require_once( "$IP/extensions/Math/Math.php" );
require_once( "$IP/extensions/Nuke/Nuke.php" );
require_once( "$IP/extensions/ParserFunctions/ParserFunctions.php" );
require_once( "$IP/extensions/Renameuser/Renameuser.php" );
require_once( "$IP/extensions/Vector/Vector.php" );
require_once( "$IP/extensions/WikiEditor/WikiEditor.php" );


# End of automatically generated settings.
# Add more configuration options below.

# Action Paths - should help with SPAM and pretty up the URLs
#               These require a a RewriteRule in the .htaccess though see
#               http://www.mediawiki.org/wiki/User:Fo0bar/MediaWiki_root_articles
#               for details.
#
#               These did not work at first because I had messed with $wgScriptPath
#               be careful.

/*
#$wgArticlePath = "/";

foreach($wgActions as $action => $value) {
  if($value === false) { continue; }
  if($action == 'raw') { continue; }
  $wgActionPaths[$action] = "$wgScriptPath/do/$action/";
}
$wgActionPaths['view'] = $wgArticlePath;
*/

# FavIcon
$wgFavicon = $wgScriptPath . "/favicon.ico";

# Don't allow the site to be iframed
$wgBreakFrames = TRUE;
# Add rel="no follow" to all links
$wgNoFollowLinks = TRUE;                // TRUE by default as of 04/11/13 but just in case

# Exceptions to the default rel="no follow" rule
$wgNoFollowDomainExceptions = array(...

# Add Equations to the Site - the URL to mathtex is in Math.body.php (function renderMath)
require_once("$IP/extensions/Math/Math.php");

# Add CAPTCHA
#               Config: http://www.mediawiki.org/wiki/Extension:ConfirmEdit
require_once("$IP/extensions/ConfirmEdit/ConfirmEdit.php");
require_once("$IP/extensions/ConfirmEdit/ReCaptcha.php");
$wgCaptchaClass = 'ReCaptcha';
$wgReCaptchaPublicKey = ...;
$wgReCaptchaPrivateKey = ...;

        # User permissions wrt CAPTCHA
        $wgGroupPermissions['*'            ]['skipcaptcha'] = false;
        $wgGroupPermissions['user'         ]['skipcaptcha'] = false;
        $wgGroupPermissions['autoconfirmed']['skipcaptcha'] = false;
        $wgGroupPermissions['bot'          ]['skipcaptcha'] = true; // registered bots
        $wgGroupPermissions['sysop'        ]['skipcaptcha'] = true;

        # Action permission wrt CAPTCHA
        $wgCaptchaTriggers['edit']          = false;            // Doesn't show CAPTCHA
        $wgCaptchaTriggers['create']        = true;
        $wgCaptchaTriggers['addurl']        = true;             // Shows CAPTCHA
        $wgCaptchaTriggers['createaccount'] = true;
        $wgCaptchaTriggers['badlogin']      = true;

        # Can also be configured to whitelist by IPs and Confirmed Emails

# Filter out all pages/edits/etc that include the following
#               Ref & more examples: http://www.mediawiki.org/wiki/Manual:$wgSpamRegex
$wgSpamRegex = "/".                        # The "/" is the opening wrapper
                "s-e-x|zoofilia|sexyongpin|grusskarte|geburtstagskarten|animalsex|".
                "sex-with|dogsex|adultchat|adultlive|camsex|sexcam|livesex|sexchat|".
                "chatsex|onlinesex|adultporn|adultvideo|adultweb.|hardcoresex|hardcoreporn|".
                "teenporn|xxxporn|lesbiansex|livegirl|livenude|livesex|livevideo|camgirl|".
                "spycam|voyeursex|casino-online|online-casino|kontaktlinsen|cheapest-phone|".
                "laser-eye|eye-laser|fuelcellmarket|lasikclinic|cragrats|parishilton|".
                "paris-hilton|paris-tape|2large|fuel-dispenser|fueling-dispenser|huojia|".
                "jinxinghj|telematicsone|telematiksone|a-mortgage|diamondabrasives|".
                "reuterbrook|sex-plugin|sex-zone|lazy-stars|eblja|liuhecai|".
                "viagra|cialis|levitra|".
                "airsoft|estate|facebook|loan|credit|garden|porn|sunless|landscaping|coupons|wartol|xbox|playstation|".
                "buy-viagra|-cialis|-levitra|boy-and-girl-kissing|". # These match spammy words
                "dirare\.com|".           # This matches dirare.com a spammer's domain name
                "overflow\s*:\s*auto|".   # This matches against overflow:auto (regardless of whitespace on either side of the colon)
                "height\s*:\s*[0-4]px|".  # This matches against height:0px (most CSS hidden spam) (regardless of whitespace on either side of the colon)
                "==<center>\[|".           # This matches some recent spam related to starsearchtool.com and friends
                "\<\s*a\s*href|".         # This blocks all href links entirely, forcing wiki syntax
                "display\s*:\s*none".     # This matches against display:none (regardless of whitespace on either side of the colon)
                "/i";                     # The "/" ends the regular expression and the "i" switch which follows makes the test case-insensitive
                                          # The "\s" matches whitespace
                                          # The "*" is a repeater (zero or more times)
                                          # The "\s*" means to look for 0 or more amount of whitespace

# Attempt to eliminate the bots
require_once( "$IP/extensions/AntiBot/AntiBot.php" );

# Citations/References
require_once("$IP/extensions/Cite/Cite.php");

# Category Tree
#               Config: http://www.mediawiki.org/wiki/Extension:CategoryTree
$wgUseAjax = true;
require_once( "$IP/extensions/CategoryTree/CategoryTree.php" );

# Wiki SEO
# Details: http://www.mediawiki.org/wiki/Extension:WikiSEO
#       Example: {{#seo: title=Your page title | titlemode= append | keywords=these,are,your,keywords | description=Your meta description }}
include_once("$IP/extensions/WikiSEO/WikiSEO.setup.php");
# Add Relation Links to Header
# Details: http://www.mediawiki.org/wiki/Extension:RelationLinks
require_once( "$IP/extensions/RelationLinks/RelationLinks.php" );

# Amazon - Doesn't make me any money but it will allow users to easily buy the
#               books
include("extensions/Amazon.php");

# Provide Section Heading Numbers
$wgDefaultUserOptions['numberheadings'] = 1;

# Provide access to outside feeds
require_once( "$IP/extensions/WikiArticleFeeds/WikiArticleFeeds.php" );
require_once( "$IP/extensions/RSS/RSS.php" );

$wgFeed = TRUE;                                                                                                                                 // Use Feed
$wgAdvertisedFeedTypes = array('rss', 'atom');  // Advertise RSS and Atom
$wgFeedCacheTimeout = 3600;                                                                                     // 1 Hour (3600 sec) between feed cache refre$
$wgFeedLimit = 15;                                                                                                                      // Number of results $

#       Dynamic Page List
#               Config: http://www.mediawiki.org/wiki/Extension:DynamicPageList_(Wikimedia)
require_once("$IP/extensions/intersection/DynamicPageList.php");
# Show Exceptions for install/dev purposes only - GTS 04/11/13
#$wgShowExceptionDetails = true;

// Prevent New Account Creation (SPAM) - GTS 06/10/13
//$wgGroupPermissions['*']['createaccount'] = false;


// Disables write access (page editing and creation) by default, creates a group named "Write", and grants it
//      write access. Users can be manually added to this group via Special:UserRights.
//      http://www.mediawiki.org/wiki/Manual:User_rights
$wgGroupPermissions['*']['edit'] = false;
$wgGroupPermissions['*']['createpage'] = false;
$wgGroupPermissions['user']['edit'] = false;
$wgGroupPermissions['user']['createpage'] = false;
$wgGroupPermissions['Write']['edit'] = true;
$wgGroupPermissions['Write' ]['createpage'] = true;
$wgGroupPermissions['sysop']['edit'] = true;
$wgGroupPermissions['sysop' ]['createpage'] = true;

--------解决方案--------

我将以下内容添加到 /etc/apache2/sites-available/wikis。controltheorypro.com.conf 然后重新启动 Apache 服务器。

# MediaWiki Security
        <Directory /var/www/html/CTP/mediawiki-1.24.2/>
                # Ignore .htaccess files
                AllowOverride All

                # Serve HTML as plaintext, don't execute SHTML
                #AddType text/plain .html .htm .shtml .php

                # Don't run arbitrary PHP code.
                #php_admin_flag engine off

                # If you've other scripting languages, disable them too.
        </Directory>

        # MediaWiki Uploads Security
        <Directory /var/www/html/CTP/mediawiki-1.24.2/images>
                # Ignore .htaccess files
                AllowOverride None

                # Serve HTML as plaintext, don't execute SHTML
                AddType text/plain .html .htm .shtml .php

                # Don't run arbitrary PHP code.
                php_admin_flag engine off

                # If you've other scripting languages, disable them too.
        </Directory>

确保您检查了以下几点: - mod_rewrite 模块已启用 - 您允许 htaccess 覆盖您想要的设置(检查,如果设置了 AllowOverwride 指令,例如(这将是最简单的值),请参阅 http://httpd.apache.org/docs/current/de/mod/core.html#allowoverride

# your directory definition
AllowOverwride All
# your other definitions

在那之后 restart/reload,短网址应该可以工作了。