Status: | effective |
Progress: | 100% |
Version: | 1.5.0+ |
Pretty URIs
Template:Interlanguagelink: en
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>.
$smwgNamespace
Sets 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
Usually, Semantic MediaWiki automatically creates the respective URIs for all resources described, e.g. see Karlsruhe in <sandbox.semantic-mediawiki.org>:
- Resource ID with content negotiation: https://sandbox.semantic-mediawiki.org/wiki/Special:URIResolver/Karlsruhe
- HTML version: https://sandbox.semantic-mediawiki.org/wiki/Karlsruhe
- RDF version: https://sandbox.semantic-mediawiki.org/wiki/Special:ExportRDF/Karlsruhe
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
However, you may want to have pretty URIs, e.g., see Karlsruhe in <www.semantic-mediawiki.org>:
- Resource ID with content negotiation: https://www.semantic-mediawiki.org/wiki/Special:URIResolver/Karlsruhe
- HTML version: https://www.semantic-mediawiki.org/id/Karlsruhe
- RDF version: https://www.semantic-mediawiki.org/wiki/Special:ExportRDF/Karlsruhe
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 <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
- Help page on function "
enableSemantics
" - Help page on configuration parameter
$smwgNamespace
Sets the namespace of exported URIs - Help page on short URLs at MediaWiki.org