Pretty URIs

From semantic-mediawiki.org
N/A
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 <www.semantic-mediawiki.org>.

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

Situation[edit]

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

Note that Special:URIResolver also accepts MediaWiki's page IDs which are better suited for linked data: in the example below, you might want to use
https://www.semantic-mediawiki.org/wiki/Special:URIResolver/?curid=123 
(because "123" ist the MediaWiki page ID of the page "Karlsruhe" in semantic-mediawiki.org.

Aim[edit]

However, you may want to have pretty URIs, e.g., see Karlsruhe in <www.semantic-mediawiki.org>:

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

Necessary steps[edit]

For that, using <www.semantic-mediawiki.org> 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 = 'https://www.semantic-mediawiki.org/id/';

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

# Rewrite to URIResolver of Semantic MediaWiki
RewriteRule ^/id/(.*) https://www.semantic-mediawiki.org/wiki/Special:URIResolver/$1 [L]

See also[edit]


References

  1. ^  |  <semantic-mediawiki.org>: GitHub issue comment gh:smwo:26:307169823
  2. ^  |  <semantic-mediawiki.org>: GitHub issue comment gh:smwo:26:307161649