Jump to content

Manual/Short URL

From Numinix MediaWiki Demo

<languages/> </tvar>.</translate>}}

<translate> Short URLs or URL Rewrites hide php file extensions from the page address.</translate> <translate> Please take a few minutes to devise a stable URL structure for your website before getting started, to reduce problems later.</translate>

<translate>

Introduction[edit]

Goal[edit]

The default MediaWiki installation path looks like this: </translate>

/var/www/html/mediawiki <translate> (installed as root user)</translate>
/home/johndoe/public_html/mediawiki <translate> (installed with a shared hosting provider)</translate>

<translate> MediaWiki's default page addresses looks like these examples: </translate>

https://example.org/w/index.php/Page_title <translate> (recent versions of MediaWiki, without CGI support)</translate>
https://example.org/w/index.php?title=Page_title <translate> (recent versions of MediaWiki, with CGI support)</translate>

<translate> Using the methods outlined on this page, we can configure something like this: </translate>

https://example.org/wiki/Page_title <translate> This is the most common configuration, same as on Wikipedia, though not the default because it requires server-side modifications</translate>
https://example.org/view/Page_title
https://wiki.example.org/view/Page_title
https://example.org/Page_title
https://wiki.example.org/Page_title

<translate> Some people do not recommend the last two configurations.</translate> <translate> See <tvar name=1></tvar> for potential problems and solutions.</translate>

<translate>

Advantages & disadvantages[edit]

  • Advantage: Short URLs hide some technical details from end-users, which can be desirable for site owners. Among other things, this means they can be kept stable when the underlying software changes.</translate> <translate> (See above for the difference between MediaWiki's default URL structure with CGI enabled vs without.)</translate> <translate> They are also easier to read, remember, and manipulate for visitors.</translate> <translate> Additionally, short URLs offer an advantage over the default URLs for Search engine optimization, as URLs containing <tvar name=1>?</tvar> can be treated less favorably by search engines when calculating page rank.</translate>

<translate>

  • Disadvantage: Requires configuration, so, depending on the hosting environment you are using, it might be difficult to recreate.</translate> <translate> However, as every widely used webserver is capable of being configured to use short URLs, most paid web hosting services should support this feature. Any host that doesn't offer you this feature is not worth your money.</translate>

<translate>

Guides[edit]

</translate> <translate> Our official guides for short URL configuration for different web servers.</translate> <translate> Pick your web server's configuration from this list.</translate> <translate> If you don't know what server software you are using, then it is most likely Apache.</translate>

  • (<translate> or</translate> LiteSpeed)

<translate>

Other how-to mini-guides[edit]

</translate> Template:Note <translate> Anyone is welcome to create a how-to solution page and list it below.</translate> <translate> Please use a sensible name for the page, one that fits in with the below names.</translate> <translate> When each unique solution has its own page, readers can skip complexity they do not want.</translate> <translate> Keep it simple, readable, short, with a separate page per separate solution.</translate>

<translate> To help others find out which Short URL methods really work, after trying each method please edit the page and increase the "worked" or "didn't_work" numbers for that guide and make a brief (or long, your choice) description on what went wrong by clicking the link on your number.

URL like - example.com/wiki/Page_title[edit]

</translate>

</tvar> are defined.</translate>}}

<translate>

Root access[edit]

</translate> <translate> These methods require that you have access to the server configuration.</translate> <translate> If you are on a shared host, you most likely don't.</translate> <translate> In this case you will be required to use a method that requires "no root access".</translate> <translate> You can jump directly to the [<tvar name=url>https://shorturls.redwerks.org/</tvar> MediaWiki ShortURL Builder tool] and follow the on-screen instructions.</translate> <translate> Select "I don't have root access" after entering your wiki's URL.</translate>




<translate> (for Apache guidance, see the link in the [[<tvar name=guides>#Guides</tvar>|Guides]] section). </translate>


<translate>

URL like - example.com/Page_title[edit]

</translate>


<translate> How to create example.com/Page_title URLs: </translate>

Template:Guide Template:Guide


<translate>

URL like - wiki.example.com/Page_title[edit]

</translate>


<translate> How to create wiki.example.com/Page_title URLs: </translate>


<translate>

Troubleshooting[edit]

Ampersand (<tvar name=1>&</tvar>) problem[edit]

</translate> <translate> The ampersand problem shows up when you have page titles with symbols in them (such as <tvar name=1></tvar>) which, despite being correctly encoded in the link, are not being passed correctly from <tvar name=2>mod_rewrite</tvar> to the script.</translate> <translate> This manifests in 404 page-not-found errors, because the title gets cut off at the special character.</translate> <translate> For example, clicking on a link to "John & Maria's page" gets a 404, because MediaWiki is looking for a page named "John ".</translate>

<translate> This is because ampersands in long-form names are treated as query string separators, and would never reach the PHP runtime environment.</translate> <translate> This is caused by an old and problematic <tvar name=1>mod_rewrite</tvar> bug.</translate><ref><translate> [<tvar name=url>https://bz.apache.org/bugzilla/show_bug.cgi?id=34602</tvar> Bugzilla <tvar name=1>mod_rewrite</tvar> for ampersand bug], partially resolved for some users, but only after 13 years</translate></ref>

<translate> Solution: </translate>

<translate> This issue is caused by the <tvar name=1>?title=$1</tvar> portion of rewrite rules like <tvar name=2>/index.php?title=$1</tvar> which is completely unnecessary and harmful.</translate> <translate> MediaWiki parses paths directly from the <tvar name=1>REQUEST_URI</tvar>, so rewrite everything to <tvar name=2>/index.php</tvar>.</translate>

<translate>

Purging cache[edit]

If you notice that your changes to <tvar name=1></tvar> in <tvar name=2>LocalSettings.php</tvar> are not being reflected in <tvar name=3>example.com/wiki/Main_Page</tvar>, it may be due to MediaWiki's caching of the links according to previous settings.

Go to <tvar name=1>example.com/wiki/Main_Page?action=purge</tvar> to force MediaWiki to regenerate the cached links.

Also you can: </translate>

  1. <translate> execute the MySQL query <tvar name=1>TRUNCATE objectcache;</tvar>, or</translate>
  2. <translate> Ensure <tvar name=2></tvar> is updated (if <tvar name=3></tvar> is enabled, all you have to do is edit <tvar name=1></tvar> to purge it)</translate>

<translate>

Redirect visitor of your domain to your wiki[edit]

Our official guides for short url configuration include recommendations on how to point the root of your site to your wiki using your short url config.

For example our [[<tvar name=1>Special:MyLanguage/Manual:Short URL/Apache</tvar>|Apache guide]] recommends using this to point your site root to your wiki: </translate>

<syntaxhighlight lang="apache"> RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L] </syntaxhighlight>

<translate> Note that we do not recommend doing a HTTP redirect to your wiki path or main page directly.</translate> <translate> As redirecting to the main page directly will hard-code variable parts of your wiki's page setup into your server config.</translate> <translate> And redirecting to the wiki path will result in two redirects.</translate> <translate> Simply rewrite the root path to MediaWiki and it will take care of the 301 redirect to the main page itself.</translate>

<translate> If using VirtualHosts, place the rewrite rules into the virtual host declaration!

Moving a wiki from <tvar name=1>/wiki</tvar> to <tvar name=2>/w</tvar>[edit]

</translate> <translate> A common beginner's mistake is to install MediaWiki itself (the source code, not the short URL) in <tvar name=1>/wiki</tvar> instead of <tvar name=2>/w</tvar>.</translate> <translate> Once installed they would realize the mistake when trying to configure Short URLs (which would become difficult as the virtual path then conflicts with the real path).</translate>

<translate> There is a manual for [[<tvar name=1>Special:MyLanguage/Manual:Moving a wiki</tvar>|moving a wiki]] in general, however that is too complicated if all you need is to change the installation directory (and stay on the same server, same database and same hostname).

Here is what you have to do:

  • Backup <tvar name=1>LocalSettings.php</tvar> and any other config files you may have created (such as your <tvar name=2>.htaccess</tvar>).</translate>

<translate>

  • Rename the installation directory of MediaWiki on your server from <tvar name=1>/wiki</tvar> to <tvar name=2>/w</tvar>.</translate>

<translate>

  • Set <tvar name=1></tvar> in <tvar name=2>LocalSettings.php</tvar> to <tvar name=3>"/w"</tvar> and remove (or comment out) any definition of <tvar name=4>$wgArticlePath</tvar> (this variable will be changed again when setting up Short URLs, further on)</translate>

<translate>

  • At this point your wiki should be working normally at <tvar name=1>example.org/w</tvar></translate>

<translate>

  • Now go through [[<tvar name=guides>#Guides</tvar>|the regular guide]] to set up short URLs</translate>

<translate>

  • Perform a few tests on your wiki to make sure nothing is broken.</translate> <translate> Edit a page, visit a few different pages, etc.</translate> <translate> If anything seems abnormal, revert the changes by restoring your backup of <tvar name=1>LocalSettings.php</tvar> and other relevant files you might have changed during configuration of short URLs and rename your folder back to <tvar name=2>/wiki</tvar>.</translate>

<translate> Note for shared hosting users: Many shared hosting plans offer an application manager to automatically Install, Update and Backup applications such as MediaWiki.</translate> <translate> If your plan has this and if you want to keep using these features, you should contact their tech support and let them know you just manually changed your MediaWiki installation directory.</translate>

<translate>

Tricks[edit]

</translate>


<translate>

See also[edit]

</translate>

  • - <translate> configuration setting that defines whether to use 'pretty' URLs or not</translate>

<translate>

  • [[<tvar name=1>Special:MyLanguage/Manual:Wiki in site root directory</tvar>|Notes on placing your wiki installation in site root directory]]</translate>
  • - <translate> configuration setting that you can use to define 'pretty' URLs for other actions, like edit or history</translate>

<translate>

  • [[<tvar name=1>Special:MyLanguage/Requests for comment/Clean up URLs</tvar>|Clean up URLs RFC]] - proposes "cleaner URLs for editing, previewing skins, etc."

External links[edit]

<translate>

  • [<tvar name=url>https://shorturls.redwerks.org/</tvar> MediaWiki Short URL Builder Tool] - A tool that can automatically generate a short url configuration more reliably than the configurations in these manual pages.</translate>

<translate>

References[edit]

</translate> <references/>


Sample content adapted from mediawikiwiki:Manual:Short_URL on mediawiki.org, licensed under CC BY-SA 4.0.