Pretty URIs

Jump to: navigation, search
Describe configuration steps on how to enable prettify URIs (or "short URIs").
Table of Contents

If one wants to have pretty URIs (or "short URIs"), more compliant to linked data principles, some settings for MediaWiki and SemanticMediaWiki are necessary. Here is how it works, exemplified for <>.

Important noteImportant Note:
It is recommended to do this setting either immediately on the initial setup of the wiki and to not change this at a later stage since the URI from configuration parameter $smwgNamespaceSets the namespace of exported URIs is used as an identifier that should not change. A change would turn the respective URI into a different entity which in fact it is not.1


Usually, Semantic MediaWiki automatically creates the respective URIs for all resources described, e.g. see Karlsruhe in <>:


However, you may want to have pretty URIs, e.g., see Karlsruhe in <>:

The expected behaviour is that the RDF version forwards to the resource ID which in turn redirects to the HTML version.2

Necessary steps

For that, using <> as an example, one needs to do:

1) Add configuration for short URLs and for the semantic namespace to your "LocalSettings.php" file:

// Pretty URIs MediaWiki
$wgScriptPath = "/";            # Path to the actual files.
$wgArticlePath = "/wiki/$1";    # Virtual path. This directory MUST be different from the one used in $wgScriptPath
$wgUsePathInfo = true;          # Enable use of pretty URLs (may not be required depending on server setup)

// Namespace configuration for Semantic MediaWiki after the enableSemantics call
$smwgNamespace = '';

2) Define alias and rewrite rules in the VirtualHost (".conf" file) on the Apache webserver

# Rewrite to URIResolver of Semantic MediaWiki
RewriteRule ^/id/(.*)$1 [L]

See also