Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Numinix MediaWiki Demo
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Manual/Short URL
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
<languages/> </tvar>.</translate>}} <translate><!--T:1--> '''Short URLs''' or '''URL Rewrites''' hide php file extensions from the page address.</translate> <translate><!--T:2--> Please take a few minutes to devise a stable URL structure for your website before getting started, to reduce problems later.</translate> <translate> == Introduction == <!--T:3--> === Goal === <!--T:4--> <!--T:5--> The default MediaWiki installation path looks like this: </translate> : <code>/var/www/html/mediawiki</code> ''<translate><!--T:6--> (installed as root user)</translate>'' : <code>/home/johndoe/public_html/mediawiki</code> ''<translate><!--T:7--> (installed with a shared hosting provider)</translate>'' <translate> <!--T:8--> MediaWiki's default page addresses looks like these examples: </translate> : <code><nowiki>https://example.org/w/index.php/Page_title</nowiki></code> ''<translate><!--T:9--> (recent versions of MediaWiki, without [[w:Common Gateway Interface|CGI]] support)</translate>'' : <code><nowiki>https://example.org/w/index.php?title=Page_title</nowiki></code> ''<translate><!--T:10--> (recent versions of MediaWiki, with CGI support)</translate>'' <translate> <!--T:11--> Using the methods outlined on this page, we can configure something like this: </translate> : <code><nowiki>https://example.org/wiki/Page_title</nowiki></code> <translate><!--T:12--> This is the most common configuration, same as on Wikipedia, though not the default because it requires server-side modifications</translate> : <code><nowiki>https://example.org/view/Page_title</nowiki></code> : <code><nowiki>https://wiki.example.org/view/Page_title</nowiki></code> : <code><nowiki>https://example.org/Page_title</nowiki></code> : <code><nowiki>https://wiki.example.org/Page_title</nowiki></code> <translate><!--T:136--> Some people do not recommend the last two configurations.</translate> <translate><!--T:137--> See <tvar name=1></tvar> for potential problems and solutions.</translate> <translate> === Advantages & disadvantages === <!--T:17--> <!--T:18--> * '''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><!--T:127--> (See above for the difference between MediaWiki's default URL structure with CGI enabled vs without.)</translate> <translate><!--T:19--> They are also easier to read, remember, and manipulate for visitors.</translate> <translate><!--T:20--> Additionally, short URLs offer an advantage over the default URLs for [[w:Search engine optimization|Search engine optimization]], as URLs containing <tvar name=1><code>?</code></tvar> can be treated less favorably by search engines when calculating page rank.</translate> <translate> <!--T:21--> * '''Disadvantage''': Requires configuration, so, depending on the hosting environment you are using, it might be difficult to recreate.</translate> <translate><!--T:22--> 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 == <!--T:23--> </translate> <translate><!--T:24--> Our official guides for short URL configuration for different web servers.</translate> <translate><!--T:25--> Pick your web server's configuration from this list.</translate> <translate><!--T:26--> If you don't know what server software you are using, then it is most likely Apache.</translate> * (<translate><!--T:135--> or</translate> LiteSpeed) * * <translate> == Other how-to mini-guides == <!--T:28--> </translate> {{note|text=<translate><!--T:29--> These guides are old and are almost entirely bad advice.</translate> <translate><!--T:30--> These will eventually be deleted one by one as our official guides above are created for different webservers.</translate>}} <translate><!--T:31--> Anyone is welcome to create a how-to solution page and list it below.</translate> <translate><!--T:32--> Please use a sensible name for the page, one that fits in with the below names.</translate> <translate><!--T:33--> When each unique solution has its own page, readers can skip complexity they do not want.</translate> <translate><!--T:34--> Keep it simple, readable, short, with a separate page per separate solution.</translate> <translate> <!--T:35--> '''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 === <!--T:36--> </translate> </tvar> are defined.</translate>}} <translate> ==== Root access ==== <!--T:39--> </translate> <translate><!--T:40--> These methods require that you have access to the server configuration.</translate> <translate><!--T:41--> If you are on a shared host, you most likely don't.</translate> <translate><!--T:42--> In this case you will be required to use a method that requires "no root access".</translate> <translate><!--T:43--> 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><!--T:131--> Select "I don't have root access" after entering your wiki's URL.</translate> <translate> <!--T:55--> (for Apache guidance, see the link in the [[<tvar name=guides>#Guides</tvar>|Guides]] section). </translate> <translate> === URL like - example.com/Page_title === <!--T:56--> </translate> <translate> <!--T:57--> How to create <code>example.com/Page_title</code> URLs: </translate> {{guide |name=Page title - nginx, Root Access, PHP as a CGI module |show=<translate nowrap><!--T:59--> Page title - nginx, Root Access, PHP as a CGI module</translate> |worked=6 |didn't_work=}} {{guide |name=Page title -- Windows & Apache without 403 on Special Pages |show=<translate nowrap><!--T:61--> Page title -- Windows & Apache without 403 on Special Pages</translate> |worked=3 |didn't_work=}} <translate> === URL like - wiki.example.com/Page_title === <!--T:64--> </translate> <translate> <!--T:65--> How to create <code>wiki.example.com/Page_title</code> URLs: </translate> <translate> == Troubleshooting == <!--T:68--> === Ampersand (<tvar name=1>&</tvar>) problem === <!--T:69--> </translate> <translate><!--T:70--> 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><!--T:71--> This manifests in 404 page-not-found errors, because the title gets cut off at the special character.</translate> <translate><!--T:72--> 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><!--T:73--> This is because ampersands in long-form names are treated as [[w:Query string|query string]] separators, and would never reach the PHP [[w:Run time (program lifecycle phase)|runtime environment]].</translate> <translate><!--T:74--> This is caused by an old and problematic <tvar name=1>mod_rewrite</tvar> bug.</translate><ref><translate><!--T:138--> [<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> <!--T:75--> '''Solution:''' </translate> <translate><!--T:76--> This issue is caused by the <tvar name=1><code>?title=$1</code></tvar> portion of rewrite rules like <tvar name=2><code>/index.php?title=$1</code></tvar> which is completely unnecessary and harmful.</translate> <translate><!--T:77--> 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 === <!--T:84--> <!--T:85--> If you notice that your changes to <tvar name=1><code></code></tvar> in <tvar name=2><code>LocalSettings.php</code></tvar> are not being reflected in <tvar name=3><code>example.com/wiki/Main_Page</code></tvar>, it may be due to MediaWiki's caching of the links according to previous settings. <!--T:86--> Go to <tvar name=1><code>example.com/wiki/Main_Page?action=purge</code></tvar> to force MediaWiki to regenerate the cached links. <!--T:87--> Also you can: </translate> # <translate><!--T:88--> execute the MySQL query <tvar name=1><code>TRUNCATE objectcache;</code></tvar>, or</translate> # <translate><!--T:89--> 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 == <!--T:90--> <!--T:91--> 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. <!--T:92--> 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><!--T:93--> Note that we do '''not''' recommend doing a HTTP redirect to your wiki path or main page directly.</translate> <translate><!--T:94--> As redirecting to the main page directly will hard-code variable parts of your wiki's page setup into your server config.</translate> <translate><!--T:95--> And redirecting to the wiki path will result in two redirects.</translate> <translate><!--T:96--> Simply rewrite the root path to MediaWiki and it will take care of the 301 redirect to the main page itself.</translate> <translate> <!--T:97--> 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> == <!--T:98--> </translate> <translate><!--T:99--> A common beginner's mistake is to install MediaWiki itself (the source code, not the short URL) in <tvar name=1><code>/wiki</code></tvar> instead of <tvar name=2><code>/w</code></tvar>.</translate> <translate><!--T:100--> 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> <!--T:101--> 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). <!--T:102--> Here is what you have to do: <!--T:103--> * Backup <tvar name=1><code>LocalSettings.php</code></tvar> and any other config files you may have created (such as your <tvar name=2><code>.htaccess</code></tvar>).</translate> <translate> <!--T:104--> * Rename the installation directory of MediaWiki on your server from <tvar name=1><code>/wiki</code></tvar> to <tvar name=2><code>/w</code></tvar>.</translate> <translate> <!--T:105--> * Set <tvar name=1><code></code></tvar> in <tvar name=2><code>LocalSettings.php</code></tvar> to <tvar name=3><code>"/w"</code></tvar> and remove (or comment out) any definition of <tvar name=4><code>$wgArticlePath</code></tvar> (this variable will be changed again when setting up Short URLs, further on)</translate> <translate> <!--T:106--> * At this point your wiki should be working normally at <tvar name=1><code>example.org/w</code></tvar></translate> <translate> <!--T:107--> * Now go through [[<tvar name=guides>#Guides</tvar>|the regular guide]] to set up short URLs</translate> <translate> <!--T:108--> * Perform a few tests on your wiki to make sure nothing is broken.</translate> <translate><!--T:109--> Edit a page, visit a few different pages, etc.</translate> <translate><!--T:110--> If anything seems abnormal, revert the changes by restoring your backup of <tvar name=1><code>LocalSettings.php</code></tvar> and other relevant files you might have changed during configuration of short URLs and rename your folder back to <tvar name=2><code>/wiki</code></tvar>.</translate> <translate><!--T:111--> '''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><!--T:112--> 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 == <!--T:113--> </translate> <translate> == See also == <!--T:117--> <!--T:118--> *[[w:Common Gateway Interface#Workarounds for scripting languages|Explanation of what CGI modules are]] </translate> * - <translate><!--T:119--> configuration setting that defines whether to use 'pretty' URLs or not</translate> <translate> <!--T:120--> *[[<tvar name=1>Special:MyLanguage/Manual:Wiki in site root directory</tvar>|Notes on placing your wiki installation in site root directory]]</translate> * - <translate><!--T:121--> configuration setting that you can use to define 'pretty' URLs for other actions, like edit or history</translate> <translate> <!--T:122--> * [[<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 == <!--T:123--> <!--T:124--> *[<tvar name=url>https://httpd.apache.org/docs/current/mod/mod_rewrite.html</tvar> Apache Module <tvar name=1>mod_rewrite</tvar>] - rewrite requested URLs on the fly</translate> <translate> <!--T:125--> *[<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> <!--T:128--> * [<tvar name=url>https://www.nngroup.com/articles/url-as-ui/</tvar> URL as UI] by [[w:Jakob Nielsen (usability consultant)|Jakob Nielsen]] on the importance of persistent, usable URLs. == References == <!--T:126--> </translate> <references/> <!--these notes are of a technical nature that the average user does not need--> [[Category:Configure|Configure]] [[Category:Wiki page URLs|Wiki page URLs]] ---- ''Sample content adapted from [[mediawikiwiki:Manual:Short_URL]] on mediawiki.org, licensed under [https://creativecommons.org/licenses/by-sa/4.0/ CC BY-SA 4.0].''
Summary:
Please note that all contributions to Numinix MediaWiki Demo may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Project:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Guide
(
edit
)
Template:Note
(
edit
)