Manual:Short URL/es-formal
Short URLs or URL Rewrites hide php file extensions from the page address. Por favor, tómese unos minutos para diseñar una estructura de URL estable para su sitio web antes de comenzar, para reducir problemas posteriores.
Introduction
Goal
The default MediaWiki installation path looks like this:
/var/www/html/mediawiki
(installed as root user)/home/johndoe/public_html/mediawiki
(installed with a shared hosting provider)
MediaWiki's default page addresses looks like these examples:
https://example.org/w/index.php/Page_title
(recent versions of MediaWiki, without CGI support)https://example.org/w/index.php?title=Page_title
(recent versions of MediaWiki, with CGI support)
Using the methods outlined on this page, we can configure something like this:
https://example.org/wiki/Page_title
This is the most common configuration, same as on Wikipedia, though not the default because it requires server-side modificationshttps://example.org/view/Page_title
https://wiki.example.org/view/Page_title
https://example.org/Page_title
https://wiki.example.org/Page_title
Some people do not recommend the last two configurations. See Manual:Wiki in site root directory for potential problems and solutions.
Advantages & disadvantages
- 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.
(See above for the difference between MediaWiki's default URL structure with CGI enabled vs without.) They are also easier to read, remember, and manipulate for visitors. Additionally, short URLs offer an advantage over the default URLs for w:Search engine optimization, as URLs containing ?
can be treated less favorably by search engines when calculating page rank.
- Disadvantage: Requires configuration, so, depending on the hosting environment you are using, it might be difficult to recreate.
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.
Guides
Our official guides for short URL configuration for different web servers. Pick your web server's configuration from this list. If you don't know what server software you are using, then it is most likely Apache.
Other how-to mini-guides
Anyone is welcome to create a how-to solution page and list it below. Please use a sensible name for the page, one that fits in with the below names. When each unique solution has its own page, readers can skip complexity they do not want. Keep it simple, readable, short, with a separate page per separate solution.
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
Root access
These methods require that you have access to the server configuration. If you are on a shared host, you most likely don't. In this case you will be required to use a method that requires "no root access". You can jump directly to the MediaWiki ShortURL Builder tool and follow the on-screen instructions. Select "I don't have root access" after entering your wiki's URL.
- wiki/Page title -- Lighttpd rewrite--root access x3
- wiki/Page title -- Cherokee rewrite--root access x1
- IIS8.5 x2 x1
- Abyss
(for Apache guidance, see the link in the Guides section).
URL like - example.com/Page_title
How to create example.com/Page_title
URLs:
- Page title - nginx, Root Access, PHP as a CGI module x6
- Page title -- Windows & Apache without 403 on Special Pages x3
URL like - wiki.example.com/Page_title
How to create wiki.example.com/Page_title
URLs:
Troubleshooting
Ampersand (&) problem
The ampersand problem shows up when you have page titles with symbols in them (such as &, ?, #, + and /) which, despite being correctly encoded in the link, are not being passed correctly from mod_rewrite to the script. This manifests in 404 page-not-found errors, because the title gets cut off at the special character. For example, clicking on a link to "John & Maria's page" gets a 404, because MediaWiki is looking for a page named "John ".
This is because ampersands in long-form names are treated as query string separators, and would never reach the PHP runtime environment. This is caused by an old and problematic mod_rewrite bug.[1]
Solution:
This issue is caused by the ?title=$1
portion of rewrite rules like /index.php?title=$1
which is completely unnecessary and harmful.
MediaWiki parses paths directly from the REQUEST_URI, so rewrite everything to /index.php.
Purging cache
Si observa que sus cambios a $wgArticlePath
en LocalSettings.php
no se reflejan en example.com/wiki/Main_Page
, puede ser debido al almacenamiento en caché de los enlaces de MediaWiki según la configuración anterior.
Go to example.com/wiki/Main_Page?action=purge
to force MediaWiki to regenerate the cached links.
También puede:
- execute the MySQL query "TRUNCATE objectcache;", or
- Asegurarse de que
$wgCacheEpoch
esté actualizado (si$wgInvalidateCacheOnLocalSettingsChange
está habilitado, todo lo que tiene que hacer es editar LocalSettings.php para purgarlo)
Redirigir al visitante de su dominio a su wiki
Nuestras guías oficiales para la configuración de URLs cortas incluyen recomendaciones sobre cómo apuntar de la raíz de su sitio a su wiki usando su configuración de URL corta.
Por ejemplo, nuestra guía de Apache recomienda usar esto para apuntar a la raíz de su sitio a su wiki:
RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]
Note that we do not recommend doing a HTTP redirect to your wiki path or main page directly. As redirecting to the main page directly will hard-code variable parts of your wiki's page setup into your server config. And redirecting to the wiki path will result in two redirects. Simplemente reescriba la ruta raíz a MediaWiki y se encargará de la redirección 301 a la página principal.
Si está utilizando VirtualHosts, ¡coloque las reglas de reescritura en la declaración del host virtual!
Moving a wiki from /wiki to /w
A common beginner's mistake is to install MediaWiki itself (the source code, not the short URL) in /wiki
instead of /w
.
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).
There is a manual for 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).
Esto es lo que tiene que hacer:
- Haga una copia de seguridad de
LocalSettings.php
y cualquier otro archivo de configuración que haya creado (como su.htaccess
). - Cambie el nombre del directorio de instalación de MediaWiki en su servidor de
/wiki
a/w
. - Establezca
$wgScriptPath
enLocalSettings.php
como"/w"
y elimine (o comente) cualquier definición de$wgArticlePath
(esta variable se modificará de nuevo al configurar las URL cortas, más adelante) - En este punto, su wiki debería estar funcionando normalmente en
example.org/w
- Ahora siga la guía habitual para configurar URLs cortas.
- Realice algunas pruebas en su wiki para asegurarse de que no haya nada roto. Edite una página, visite algunas páginas diferentes, etc. Si algo parece anormal, revierta los cambios restaurando su copia de seguridad de
LocalSettings.php
y otros archivos relevantes que pueda haber cambiado durante la configuración de URLs cortas y renombre su directorio de nuevo a/wiki
.
Note for shared hosting users: Many shared hosting plans offer an application manager to automatically Install, Update and Backup applications such as MediaWiki. Si su plan tiene esto y desea seguir usando estas funciones, debe comunicarse con su soporte técnico e informarles que acaba de cambiar manualmente su directorio de instalación de MediaWiki.
Tricks
See also
- $wgUsePathInfo - configuration setting that defines whether to use 'pretty' URLs or not
- $wgActionPaths - configuration setting that you can use to define 'pretty' URLs for other actions, like edit or history
- Clean up URLs RFC - proposes "cleaner URLs for editing, previewing skins, etc."
External links
- Apache Module mod_rewrite - rewrite requested URLs on the fly
- MediaWiki Short URL Builder Tool - A tool that can automatically generate a short url configuration more reliably than the configurations in these manual pages.
- URL as UI by Jakob Nielsen on the importance of persistent, usable URLs.
References
- ↑ Bugzilla mod_rewrite for ampersand bug, partially resolved for some users, but only after 13 years