Manual talk:Short URL/Apache

Jump to navigation Jump to search

About this board

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

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

Thanks for the MediaWiki ShortURL Builder

Summary by Berot3

I wanted to say thanks, many many thanks

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

Summary by Berot3

seems like nobody is using Lighttpd? closing for now.

Tinker Bell (talkcontribs)

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

Some pages have links (on buttons) that do not obey this setup

Summary by Berot3

"MediaWiki's short urls only apply to simple page views." (talkcontribs)

I achieved what was promised - short URL's, for most pages.

However, there are pages that generate URL's to other pages that do not respect this setup.

For example, after setting it all up, I tried to uplaod a sample picture and then delete it.

"Delete" link on that page is generated to use NOT pretty version of the url, ie: /w/index.php?action-delete&...

Same for many other links that are action "buttons": Go button on running queires on secial pages, link to view current user account - all have non-magled, un-pretty url in them;

My guess, php code behind those pages does not use $wgArticlePath variable, but instead uses raw $wgScriptPath, which causes them to generate links against this setup;

Also, upload page actions do not fall under posted rewrite rules. uploaded images were not always showing up. Had to add another rule to rewrite prefix of urls generated with $wgUploadDirectory

Dantman (talkcontribs)

MediaWiki's short urls only apply to simple page views. Most URLs with queries in them point to index.php so that they can be included in robots.txt. Some &action= urls can be made to use a different short url if you configure $wgActionPaths for them.

Cann't get this extension working

Summary by Berot3

probably not relevant anymore

Solanki (talkcontribs)


I am not able to get this extension working. All my efforts either ends up in 400 not found or Bad Request.

what I am doing is, added following in my LocalSettings.php

$wgArticlePath = "wiki/$1";
$wgUsePathInfo = false;

Added following in httpd.conf file:

LoadModule rewrite_module modules/

<syntaxhighlight lang="php" strict>
<VirtualHost IP:port no>
RewriteEngine On
DocumentRoot "/path/to/apache/webroot/"

<Directory /path/to/apache/webroot/>
AllowOverride All
Require all granted

RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/Mediawiki-1.23/index.php [L]

Value for following variables are:

$wgArticlePath = "/wiki/$1";
$wgScriptPath = "/Mediawiki-1.23";

What I am expecting is, that in the browser I should get the URL as "http://IP/Mediawiki-1.23/ " (w/o the index.php) and also it should be able to navigate within the wiki w/o having the index.php in the URL. I am trying this on Apache 2.4 and PHP 5.4. Please suggest, how can I get this working?

Dantman (talkcontribs)

$wgArticlePath = "wiki/$1"; is wrong, it must start with /.

Besides that it doesn't look like you have followed the guide at all.

The -f and -d don't apply when doing /wiki/$1 urls and mediawiki is in a separate folder and they're in the wrong spot.

And there is no mention anywhere of RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L], which is likely intercepting any url belonging to your wiki and sending it somewhere else.

Solanki (talkcontribs)

Actually, when I wasn't able to make it work, I took reference from many sources and clubbed too many parameters in the hope that it would work. Apparently, now it works, Thanks to you. The only thing I am wondering now, is how to get it working for every links within the wiki like the way it is working for main page.

Dantman (talkcontribs)

If it doesn't work outside the main page, are you sure $wgArticlePath is set right?

Solanki (talkcontribs)

I have set: $wgArticlePath = "/wiki/$1"; What I am trying to say is, if u crate a new page, then the URL for that page must behave in the same manner, but here it isn't. So, Is there any thing else I need to take care of?

Never applies the rules even when AllowOverride is on.

3 (talkcontribs)

Centos 7, Apache 2.4.6

So, I am trying to short URL like this:


[Edit: I changed this from to Sorry, I originally wrote this after doing command line for about 8 hours straight.]

I have mod_rewrite enabled:

grep -i LoadModule /etc/httpd/conf/httpd.conf | grep rewrite


LoadModule rewrite_module modules/

I have a symbolic link called "fts" that points to the root folder of the wiki documents.

I go to my root folder of my wiki documents:

cd /var/www/html/mediawiki-1.24.1 
sudo vim .htaccess

and then I create this .htaccess file

# Enable the rewrite engine
RewriteEngine On
# Short url for wiki pages
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/fts/index.php [L]
# Redirect / to Main Page
RewriteRule ^/*$ %{DOCUMENT_ROOT}/fts/index.php [L]

Then I load up my wiki and nothing is different. So, I go back to to httpd.conf and make sure AllowOverrides All is on:

grep -i AllowOverride /etc/httpd/conf/httpd.conf


AllowOverride None
AllowOverride All <--- this is the <Directory "/var/www/html"> section one
AllowOverride None
AllowOverride None

What's up here? I can't figure out why nothing is going on. I'm restarting httpd every time I do an edit to anything.

Ciencia Al Poder (talkcontribs)

Note that only adding stuff to apache config files doesn't automagically make MediaWiki aware of the new URL scheme. You should change $wgArticlePath accordingly so MediaWiki generates URLs following that scheme.

You said you want your URLS to be, but you set up rules for URLs like

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

Also note that the URL scheme you propose is not recommended, since there are more paths under your domain that shouldn't be treated as wiki pages. Looks like you're missing reading/understanding some important parts of the manual.

And I don't understand why do you have a fts link pointing to the parent folder. That's really awkward.

Using Alias instead of RewriteEngine

Jcrummy (talkcontribs)

I was unable to get this working using RewriteEngine, however using Alias did. I added:

 Alias /wiki "/var/www/html/w/index.php/"

And everything works great. I did this in httpd.conf, which won't work if you don't have access to it.

Is there any reason why this wouldn't be a good idea?


Dantman (talkcontribs)

Alias basically turns /wiki/Foo into /w/index.php/Foo rather than just telling Apache to load index.php. I can't remember the specific things that ended up different but it isn't ideal.

In what way did it break when you tried configuring it with RewriteEngine? Was it a 404 or a 500 error? If it was a 500 error, what showed up in the error log?

Berot3 (talkcontribs)

If you google ''alias vs rewrite" you will find that apache recommends alias over rewrite. Mediawiki is special, butb I did not read of any problems with alias. Do you?

Also what do you mean by "just telling Apache to load index.php", to me it looks like alias and rewrite are both replacing one with the other, dont they?

Reply to "Using Alias instead of RewriteEngine"

What does it mean when it says: "The MediaWiki directory is located at: /w" ?

Gareth.randall (talkcontribs)

I have a question on the very first requirement in this guide.

Quote: "The MediaWiki directory is located at: /w"

What does this mean?

  1. The mediawiki tar has been extracted in to /var/lib/mediawiki, and then a symlink named "w" has been created in /var/www/html/ to point to /var/lib/mediawiki ?
  2. The mediawiki tar has been extracted in to /w . I.e. a directory called /w on the root of the server filesystem ?
  3. There is no physical "w" directory on in the filesystem. There is an alias in one of the Apache config files (which one and in what section?) of the form: "Alias /w /var/lib/mediawiki"
  4. Or something else?

Can this be clarified please, perhaps with an example of every place where /w is referenced so that any attempt to change it will get all of the occurrences? Thanks. (talkcontribs)

Something else: It means the tarball has been extracted into the folder /w. Later down the page we expect that this folder is located directly inside the webroot. E.g. if your webroot is /var/www, then /w would have to be /var/www/w/.

Multiple MW installations on one Apache

Pdr3112 (talkcontribs)

I have multiple MW installations on a single Apache Webserver. The steps given here mention the short URLs considering that there is only one MW installation per Webserver.

Anyone got an idea as to what to do do to make multiple clean URLs on multiple installations but on same Webserver.

eg: http://<generic URL>/<specific installation 1>/Page_name_X http://<generic URL>/<specific installation 2>/Page_name_Y

For security and company policy reasons cannot share the exact installations or paths as it is not live yet on Internet.

MW: 1.18.2 Apache HTTPD: 2.4 PHP: 5.3.5 Postgres: 9.2

Dantman (talkcontribs)

Configure your wiki one at a time, the technique you use will vary depending on how the directories intersect.

If your multiple wiki are setup like this:

You won't need to do anything special at all. .htaccess files only need to be high enough up in the path that they are above both the /index.php and /wiki/ paths. So you'll have /departmentA/.htaccess and /departmentB/.htaccess and wont need to do anything.

If your multiple wiki aresetp like this:

Then the wiki will share a common root since for a .htaccess to apply to both /departmentA_wiki and /departmentA it would need to be in the root .htaccess. But it won't be too hard, the rules that setup your short urls don't intersect so all you'll do is put the config you get for both wiki into the same /.htaccess file.

The only tweaks you'll want to make to what you get are that you'll only need one RewriteEngine On and you might want to remove the RewriteRule ^/?$ %{DOCUMENT_ROOT}/w/index.php [L] line that redirects the site root to the wiki's mainpage.

GregariousJB (talkcontribs)
  • MediaWiki 1.23
  • Apache 2.4.9
  • MySQL 5.6.17
  • PHP 5.5.12

To duplicate:

  1. Go to
  2. Enter this URL:
    • Error: Encountered invalid XML while trying to find the API
  3. Enter this URL:
    • Error: Sorry, this does not look like a wiki.
  4. Enter this URL:
    • (Massive 403 "Forbidden" error that fills the screen)

If it helps, I'm hosting it on my own computer using WAMP, and a DNS host record via However, using only my IP gives me the same error.

On a side note, the website can easily be made more informative. An example URL near the form would tell us how the URL might look and what we need to include. Also, you're playing with fire when you write three large paragraphs of text instead of short, concise instructions in a numbered list. The same can be said of the Manual:Short_URL/Apache page. It's really long and confusing.

Dantman (talkcontribs)

Your site isn't available at the moment so I can't debug the errors.

The first error typically happens when your site outputs PHP errors/notices due to something broken in an extension or your settings file.

I've added a placeholder to the url input in the dev version, I'll look into improving the page tomorrow, then deploy it.