Extension:Enforce Correct Virtual Host

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
Enforce Correct Virtual Host

Release status: unknown

Implementation User interface
Description A default servername is defined. Requests with other servernames are redirected to default server name.
Author(s) Xypron
License No license specified
Download This page
Parameters

$xygVirtualHost

Check usage (experimental)

Contents

[edit] Why is this extension needed?

One single wiki may be reachable with different URLs, e.g.

  • http://wiki.myorg.org/index.php
  • http://69.124.251.206/index.php
  • http://wiki/index.php
  • http://localhost/index.php

This will create two types of problems:

  • External links will not be unique and not valid from all environments. E.g. http://localhost/index.php will not be reachable from other computers.
  • Using interwiki links to same system will force users to log on again: Take a wiki with articles in German and English. Namespaces en and de have been defined in table interwiki to point to the wiki itself. If the server part of the url changes when following an interwiki link (to the same wiki but different language) the logon is lost as the session cookie is only valid for one server name.

[edit] What does this extension do?

A default servername is defined. Requests with other servernames are redirected to default server name.

As users will always use the same server name the problems described above are solved.

[edit] How to install this extension

  • Copy the script below to /extensions/xyEnforceVirtualHost.php.
  • Change file LocalSettings.php, eg:
$xygVirtualHost = 'wiki.myorg.org';
require_once('extensions/xyEnforceVirtualHost.php');

[edit] The script

<?php
/**
 * Enforce correct virtual host.
 *
 * filename xyEnforceVirtualHost.php
 * @author  xypron
 * @version 2006-08-04
 *
 * Our wiki installation may be reachable on different virtual hosts, e.g.
 *   http://wiki.myorg.org/index.php
 *   http://69.124.251.206/index.php
 *   http://wiki/index.php
 *   http://localhost/index.php
 *
 * To ensure correct external linking users should only use one single virtual host.
 *
 * Installation
 *   Save this file to /extensions/xyEnforceVirtualHost.php.
 *   Change file LocalSettings.php, eg:
 *     $xygVirtualHost = 'wiki.myorg.org';
 *     require_once('extensions/xyEnforceVirtualHost.php');
 */
if ($xygVirtualHost) {
  if ($_SERVER['SERVER_NAME'] != $xygVirtualHost) {
    $uri = $_SERVER['REQUEST_URI'];
    header("Location: http://$xygVirtualHost$uri");
    die();
    }
  }

[edit] Tested environments

The extension has been successfully tested in the following environments:

  • Linux
    • MediaWiki 1.5.8
    • Apache/2.0.50 (Fedora)
    • PHP 4.3.8
    • MySQL 3.23.58
  • Windows 2000 prof
    • MediaWiki 1.8 alpha rev. 15483
    • Apache 2.0.49
    • PHP Version 5.1.1
    • MySQL - 5.0.23-community-nt
Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox