How to add namespace aliases in MediaWiki
Each page on your MediaWiki site belongs to a namespace. MediaWiki comes preconfigured with 18 default namespaces. In addition to these you can also create custom ones. Users can choose in which namespace to create a page based on its function. The main content pages (or articles as they are known), for example, are stored in the Main namespace.
Every namespace has a name that's used on the frontend as a prefix to the names of the pages in that namespaces, and also a prefix in their respective URL addresses. For instance, a page with the name Example Page that's in the Help namespace will have a full name Help:Example Page, and it's URL will have the form yourdomain.com/index.php/Help:Example_Page. The only namespace that doesn't have a prefix is the Main namespace.
There's an option with which you can add aliases to namespaces, both to the prepackaged default namespaces and to custom ones that you've created. When somebody uses an alias in the URL or with the search function of the site, they will automatically be redirected to the namespace with which the alias is associated. For example, if you add the alias Tutorials for the namespace Help and somebody opens the URL yourdomain.com/index.php/Tutorials:Example_Page, then they will be automatically redirected to yourdomain.com/index.php/Help:Example_Page.
A namespace can have more than one alias.
Aliases are created by adding the option $wgNamespaceAliases with the necessary information to the LocalSettings.php file of your MediaWiki. As you know, a namespace has a corresponding talk namespace for pages used for discussions and comments. So when adding an alias for a non-talk namespace it's a good idea to add an alias for its associated talk namespace. For example, by adding the following on new lines at the end of LocalSettings.php:$wgNamespaceAliases['Tutorials'] = NS_HELP; $wgNamespaceAliases['Tutorials_talk'] = NS_HELP_TALK;
you'll create an alias Tutorials for the Help namespace and an alias Tutorials talk for the Help talk namespace. Note that if the alias consists of more than one word, they should be separated with underscores (e.g. Tutorials_talk).
A namespaces is defined with an ID number and a text constant. When you add an alias you should use either the ID number or the constant of the namespace for which you want the alias to apply. In our example, we've added aliases for the Help and Help talk namespaces which have the constants NS_HELP and NS_HELP_TALK respectively. Their corresponding ID numbers are 12 and 13. So you can also add the same aliases to these namespaces with the following:$wgNamespaceAliases['Tutorials'] = 12; $wgNamespaceAliases['Tutorials_talk'] = 13;
For a list of the default namespaces with their IDs and constants check in our knowledge base the references list of MediaWiki namespaces with their ID numbers and constants. If you're adding an alias for a custom namespace one way to check its ID and constant is to find it in the LocalSettings.php file.
If you want to add an alias for more than one namespace (or more than one alias for a namespace), instead of adding each alias by adding the option $wgNamespaceAliases separately, an alternative is to use an array of aliases. For example:$wgNamespaceAliases = array( 'Main_Discussion' => NS_TALK, 'Uploads' => 6 );
will create an alias Main Discussion for the Talk namespace and an alias Uploads for the File namespace.
It's up to you which of the two ways you'll use. They have the same effect. Note however that if you have namespace aliases added with single lines as in our first example, and you then under them in the LocalSettings.php file you add more aliases with an array, as in our second example, those aliases that are added with separate lines will not work. The reverse is not a problem; if you have an array of namespace aliases and then further down in the LocalSettings.php file you add more aliases with separate lines, they will all work fine.
The LocalSettings.php file that you have to modify to add namespace aliases is in the root MediaWiki folder of your MediaWiki hosting account. For example, if the application is installed directly in the public_html directory, the path on the account to the file in relation to that directory will be public_html/LocalSettings.php. HostKnox customers can use the File manager of the Pixie control panel to view and edit files. Another way is to download it on your local computer, edit it with a text editor (e.g. Notepad ++) and upload it back replacing the old file.
In our knowledge base there are some other articles related to namespaces that you may find useful:
- how to select the default namespaces to be searched by the search function in MediaWiki
- how to limit the sitemap to specific namespaces in MediaWiki
- how to turn namespaces into content namespaces in MediaWiki
- how to check the ID number of a namespace in MediaWiki
- reference list of MediaWiki namespaces and their ID numbers and constants
Was this answer helpful?
- How to disable and enable user account creation in MediaWiki
- How to set and change the favicon in MediaWiki
- How to remove from the footer the information about the last modification and view count of pages in MediaWiki
- How to remove personal user links from the header in MediaWiki
- How to make CSS modifications in MediaWiki