Manual talk:Short URL/Apache

Jump to navigation Jump to search

About this board

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:
  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'] == '' && substr($_SERVER['REQUEST_URI'], 0, 3) == '/en') {
        $wikiId = 'en';
    } elseif (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME'] == '' && 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 = "";
    ## 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} ^($
    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.

Reply to "My example wikifarm"
2601:8C1:8380:BC40:D3C:64CD:83E0:A6AC (talkcontribs)

I followed the guide, yet I can only get the articles under /wiki/ . I need to get the editing page options under /wiki/ aswell. If anyone can help I will appreciate it!

Reply to "Running in a container"

Thanks for the MediaWiki ShortURL Builder

2001:8003:7CCF:FC00:D408:6760:A405:E1A2 (talkcontribs)

I'm not sure whether this discussion is just to flag problems, but I wanted to shout a big THANKS to whoever put together the MediaWiki ShortURL Builder. I'm a new MediaWiki user, and not a programmer, so I find these technical bits scary. This builder worked great for me, I wanted to say thanks, many many thanks :)

Reply to "Thanks for the MediaWiki ShortURL Builder"

What about colons issue on Windows for Special Pages?

Mirrabeau (talkcontribs)
Reply to "What about colons issue on Windows for Special Pages?"

%{DOCUMENT_ROOT} on windows creates 403 error

1 (talkcontribs)

On local Windows 10 apache installation %{DOCUMENT_ROOT} on windows creates 403 error.


# Enable the rewrite engine

RewriteEngine On

# Short URL for wiki pages

RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]

# Redirect / to Main Page

RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]

You don't have permission to access /G:/WebSites/pw/w/index.php on this server.

[Sun Nov 18 10:55:39.710853 2018]


[pid 11584:tid 1264] (20023)

The given path was above the root path:

[client] AH00127: Cannot map GET / HTTP/1.1 to file

This configuration however works fine:


# Enable the rewrite engine

RewriteEngine On

# Short URL for wiki pages

RewriteRule ^/?wiki(/.*)?$ /w/index.php [L]

# Redirect / to Main Page

RewriteRule ^/*$ /w/index.php [L]

Reply to "%{DOCUMENT_ROOT} on windows creates 403 error"
Tinker Bell (talkcontribs)

Is there a way to do this, using lighttpd mod_rewrite?

Reply to "Lighttpd"
Pangaearocks (talkcontribs)

I've read this, and a wide range of other pages I've found in searches, and still have no clue how to get this ShortURL malarky working. Can somebody help me out? I've installed on localhost, so have root access. But when I try to write these rules and try to restart Apache, I'm met with an error message like below:

AH00526: Syntax error on line 14 of /etc/apache2/sites-enabled/000-default.conf:

Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

Where and exactly how am I suppose to set up this stuff?? Am I supposed to put these lines of RewriteEngine and such inside some type of tags??

Hopefully I'm fiddling with the right file at least, but this is the entirety of it.

<VirtualHost *:80>

   # The ServerName directive sets the request scheme, hostname and port that

   # the server uses to identify itself. This is used when creating

   # redirection URLs. In the context of virtual hosts, the ServerName

   # specifies what hostname must appear in the request's Host: header to

   # match this virtual host. For the default virtual host (this file) this

   # value is not decisive as it is used as a last resort host regardless.

   # However, you must set it for any further virtual host explicitly.


   ServerAdmin webmaster@localhost

   DocumentRoot /var/www/html

   # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,

   # error, crit, alert, emerg.

   # It is also possible to configure the loglevel for particular

   # modules, e.g.

   #LogLevel info ssl:warn

   ErrorLog ${APACHE_LOG_DIR}/error.log

   CustomLog ${APACHE_LOG_DIR}/access.log combined

   # For most configuration files from conf-available/, which are

   # enabled or disabled at a global level, it is possible to

   # include a line for only one particular virtual host. For example the

   # following line enables the CGI configuration for this host only

   # after it has been globally disabled with "a2disconf".

   #Include conf-available/serve-cgi-bin.conf


# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Ciencia Al Poder (talkcontribs)
Pangaearocks (talkcontribs)

Thank you, that got me a little further. The wiki loads, but the main page looks weird, with the sidebar on the very bottom, and with seemingly no css. If I try http://localhost/wiki/Main_Page, however, there is a Not found error message.

Is there an example somewhere of what these files are supposed to look like when completed and working?

Right now my sites-available .conf holds (with the comments sections removed):

<VirtualHost *:80>

	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html

RewriteEngine On
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/index.php [L]

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined


# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

While the LocalSettings.php file has:

## 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:


$wgScriptPath = "";

$wgScriptExtension = ".php";

$wgArticlePath = "/wiki/$1";

## The protocol and server name to use in fully-qualified URLs

$wgServer = "http://localhost";

## The URL path to static resources (images, scripts, etc.)

$wgResourceBasePath = $wgScriptPath;

Some of that was gotten to by using Perhaps it is completely messed up, but it's hard to understand what is supposed to be written in the files.

Reply to "Horribly confused"

ShortURL constantly returns 404 Not Found

9 (talkcontribs)


MediaWiki 1.30.0

PHP 7.1.16 (apache2handler)

MariaDB 5.5.56-MariaDB

ICU 50.1.2

I have a mediawiki running on a directory, /mw/ and it generates the /mw/index.php/Article

I just want to remove the index.php section.

I have root access and have run Redworks' ShortURL tool. My ShortURL stuff to go into my virtual host is as follows:

RewriteEngine On



RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/mw/index.php [L]

And my LocalSettings.php

$wgScriptPath = "/mw";

$wgScriptExtension = ".php";

$wgArticlePath = "{$wgScriptPath}/$1";

It seems to work, but I constantly get a 404 Not Found error. It redirects but doesn't actually process.

I cannot get it to work no matter what. Any help would be appreciated.

Ciencia Al Poder (talkcontribs)

If your index.php path is at /mw/index.php, you should't make your URLs look like /mw/$1, because this is a source of conflicts.

Please choose a different scheme, for example, articles in /wiki/$1 (talkcontribs)

I did. Even using /wiki/$1 I get a 404 Not Found error. Below is my info:

RewriteEngine On

RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/mw/index.php [L]

RewriteRule ^/?$ %{DOCUMENT_ROOT}/mw/index.php [L]

$wgScriptPath = "/mw";

$wgScriptExtension = ".php";

$wgArticlePath = "/wiki/$1";

It writes to /wiki/ fine but I still get a 404 error.

Ciencia Al Poder (talkcontribs)

The configuration looks good.

If you access the "/mw/index.php" path from your browser, does it display the main page? (talkcontribs)

If I put index.php/Main_Page, yes.

If I put index.php/ it redirects around as /wiki/

Ciencia Al Poder (talkcontribs)

Be sure there's no folder named "wiki" on the webserver (talkcontribs)

There isn't.

Ciencia Al Poder (talkcontribs)

I think your rewrite rules are not being taken into account by the webserver. Maybe server admin disabled the ability to override/create rewrite rules. (talkcontribs)

Провозился 2 дня. Всё делал как в инструкциях... Переустанавливал вики, специально в подкаталог "w". Всё время выдавало 404, при этом путь менялся как нужно //сайт/wiki/Page_title

Настраивал через .htaccess . В итоге просто нужно .htaccess поместить рядом с папкой "w". До этого был на каталог выше. После всё заработало.

Reply to "ShortURL constantly returns 404 Not Found"
Brickscrap (talkcontribs)

I've followed the Apache instructions to the letter, and just get a 404 error. Straight up doesn't work, and I can't figure out why. Tried putting the rules in 000-default.conf, and mediawiki.conf, and apache2.conf (one at a time), and still nothing. AllowOverride is set to All as well.

Running Ubuntu 18, any thoughts?

Brickscrap (talkcontribs)

Ok so my Wiki is on port 8081 and the VirtualHost was set to 80, so it kind of works now, but when I visit the page it's completely broken, all formatting etc... Have tried everything I can think of, including what's posted below, but nothing...

Ciencia Al Poder (talkcontribs)

Hit F12, open the network tab and reload the page. Look at any error in requests (like HTTP status 404, 400, 500...), and figure out if the URL it's trying to request makes sense. If it makes sense, problem is in apache config. If not, problem is in MediaWiki config.

Reply to "Not working on Ubuntu"

Sidebar and Images with Short URL

Sojourner9 (talkcontribs)

Followed the instructions for apache - wound up with a mess of formatting and no images.

If this helps others - had to do the following to get it to work:

In the apache2.conf file:

## don't rewrite load.php, api.php, and other php scripts.  this got the sidebar and CSS/formatting to work
RewriteRule ^/?wiki.*\.php - [L]

## don't rewrite images/icons in the resources folder.  this got icons to work
RewriteRule ^/?wiki/resources - [L]

## rewrite to short url
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/wiki/index.php [L,QSA]

I suspect I'll need to do a "not images" type of rule also, but haven't uploaded any images to this wiki yet.

Reply to "Sidebar and Images with Short URL"