Topic on Manual talk:Short URL/Apache

Summary by Berot3

"I followed the wikimedia style, which has the language wikis as third level domains"

Lwangaman (talkcontribs)

I just wanted to share my setup of a wikifarm for a multi-language wiki using the same mediawiki installation. After a few days of trial and error I finally seem to have it working, but I didn't use any of the automatically generated scripts that probably wouldn't have worked in my case. In any case this is my setup.

  1. I have installed the mediawiki package in a subdomain, let's call it: https://mywiki.example.com
  2. After doing some initial customizations, I took the next step to make a wikifarm for different languages. I copied the "template" database tables of my initial installation to two other database tables with language suffixes ("_en" and "_it")
  3. I created two aliases in my apache vhost file, one for each of the languages that I will currently support:
    Alias /en/ /var/wikiinstallationpath
    Alias /it/ /var/wikiinstallationpath
  4. I added logic in the LocalSettings to pick up on the language based on the url "subdirectory":
    #Let's try to setup a wiki family
    if ( defined( 'MW_DB' ) ) {
        // Set $wikiId from the defined constant 'MW_DB' that is set by maintenance scripts.     $wikiId = MW_DB;
    } elseif (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME'] == 'mywiki.example.com' && substr($_SERVER['REQUEST_URI'], 0, 3) == '/en') {
        $wikiId = 'en';
    } elseif (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME'] == 'mywiki.example.com' && substr($_SERVER['REQUEST_URI'], 0, 3) == '/it') {
        $wikiId = 'it';
    } else {
        // Fail gracefully if no value was set to the $wikiId variable, i.e. if no wiki was determined
        die( 'It was not possible to determine the wiki ID.' );
    }
  5. Then I use that wikiID to choose the database:
    # MySQL specific settings $wgDBprefix = "";
    $wgDBname = 'mywiki_' . $wikiId;
    $wgSharedDB = 'mywiki';
    $wgCacheDirectory = "/tmp/mediawiki_".$wikiId."_cache";
    $wgUploadDirectory = "$IP/images";
    $wgUploadPath = "/images";
  6. Seeing that the language "subdirectories" are aliased to the script path by apache, I figure I can tell mediawiki that my script path is in the language subdirectory (physically non existent, virtually an alias of the real script path): $wgScriptPath = "/$wikiId";
    $wgScriptExtension = ".php";
    $wgArticlePath = "{$wgScriptPath}/$1";
    $wgUsePathInfo = true;
    $wgServer = "https://mywiki.example.com";
    ## The URL path to static resources (images, scripts, etc.)
    $wgResourceBasePath = $wgScriptPath;
  7. Then I have an .htaccess in my root directory:
    RewriteEngine On
    #For the time being we don't use the base hostname, if requested we redirect to the english version
    RedirectMatch ^/$ /en/
    #Let's do Short URLs
    RewriteCond %{HTTP_HOST} ^(mywiki.example.com)$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php [L]

With this current setup, I am successfully serving my pages with short URLs, and the interwiki links are also being generated as short urls. Interwiki links between languages are working nicely too. Now that I've installed the Wikibase extension I just have to figure out how to populate the sites table and use sitelinks to link between my two languages.

Berot3 (talkcontribs)

nice. how did it go with the wikibase after 7 months? :)

Lwangaman (talkcontribs)

I have actually changed the setup since then. Something eventually went haywire after only a month or so, at first I thought it was spam but maybe it was jobs not being setup correctly. In any case the wiki suddenly stopped being accessible, and I really didn't know where to start to get it up and running again, so I just wiped it out and started all over. This time I followed the wikimedia style, which has the language wikis as third level domains; in my case, the language wikis are fourth level domains. Which in my opinion is a little less accessible than I would like it, but it works. I also made sure to read through everything that has to do with combating spam, and so I set up a few daily jobs to keep the antispam up to date. Wikibase is currently working well, and I have language links between the wikis working nicely.

Berot3 (talkcontribs)

great! I also think that the mediawiki way for language isnt too bad :)