Manual:URL corto

From mediawiki.org
This page is a translated version of the page Manual:Short URL and the translation is 53% complete.
Este artículo trata sobre la estructura de los localizadores de recursos uniforme (URL). Para crear URLs cortas para artículos, véase Extensión:ShortUrl . Para crear un servicio de acortado de URL, véase Extension:UrlShortener .

Las URL cortas o las reescrituras de URL ocultan las extensiones de archivos php de la dirección de la página. 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.

Introducción

Objetivo

La ruta de instalación por defecto de MediaWiki se ve así:

/var/www/html/mediawiki (instalado como usuario root)
/home/johndoe/public_html/mediawiki (instalado con un proveedor de alojamiento compartido)

Las direcciones de las páginas predeterminadas de MediaWiki se parecen a estos ejemplos:

https://example.org/w/index.php/Page_title (versiones recientes de MediaWiki, sin soporte de CGI)
https://example.org/w/index.php?title=Page_title (versiones recientes de MediaWiki, con soporte de CGI)

Usando los métodos descritos en esta página, podemos configurar algo como esto:

https://example.org/wiki/Page_title Esta es la configuración más común, la misma que en Wikipedia, aunque no es la predeterminada porque requiere modificaciones del lado del servidor
https://example.org/view/Page_title
https://wiki.example.org/view/Page_title
https://example.org/Page_title
https://wiki.example.org/Page_title

Algunas personas no recomiendan las dos últimas configuraciones. Véase Manual:Wiki in site root directory para encontrar posibles problemas y soluciones.

Ventajas y desventajas

  • 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

Nuestras guías oficiales para la configuración de URLs cortas para diferentes servidores web. Elija la configuración de su servidor web de esta lista. Si no sabe qué software de servidor está utilizando, entonces lo más probable es que sea Apache.

Otras miniguías prácticas

These guides are old and are almost entirely bad advice. These will eventually be deleted one by one as our official guides above are created for different webservers.

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

Actions such as edit, view history, etc. will still have index.php unless $wgActionPaths are defined.

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.

(for Apache guidance, see the link in the Guides section).

URL like - example.com/Page_title

Some people do not recommend this configuration. See Manual:Wiki in site root directory for potential problems and solutions.

How to create example.com/Page_title URLs:

URL like - wiki.example.com/Page_title

Some people do not recommend this configuration. See Manual:Wiki in site root directory for potential problems and solutions.

How to create wiki.example.com/Page_title URLs:

Solución de problemas

Problema con Ampersand (&)

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]

Solución:

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.

Purga de la caché

If you notice that your changes to $wgArticlePath in LocalSettings.php are not being reflected in mysite.com/wiki/Main_Page, it may be due to MediaWiki's caching of the links according to previous settings.

Go to mysite.com/wiki/Main_Page?action=purge to force MediaWiki to regenerate the cached links.

Also you can:

  1. execute the MySQL query "TRUNCATE objectcache;", or
  1. Ensure $wgCacheEpoch is updated (if $wgInvalidateCacheOnLocalSettingsChange is enabled, all you have to do is edit LocalSettings.php to purge it)

Redirigir al visitante de tu dominio a tu wiki

Nuestras guías oficiales para la configuración de URLs cortas incluyen recomendaciones sobre cómo apuntar de la raíz de tu sitio a tu wiki usando tu configuración de URL corta.

Por ejemplo, nuestra guía de Apache recomienda usar esto para apuntar a la raíz de tu sitio a tu wiki:

RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]

Nótese que no recomendamos hacer una redirección HTTP a la ruta de tu wiki o a la página principal directamente. Al redirigir directamente a la página principal, partes de las variables de la configuración de la página de tu wiki se incorporarán a la configuración del servidor. Y redirigir a la ruta wiki, resultará en dos redirecciones. Simplemente reescriba la ruta raíz a MediaWiki y eso 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!

Moviendo una wiki de /wiki a /w

Un error común de los principiantes es instalar la propia MediaWiki (el código fuente, no la URL corta) en /wiki en lugar de /w. Una vez instalada se darían cuenta del error al tratar de configurar las URL cortas (lo cual se volvería difícil, ya que la ruta virtual entra en conflicto con la ruta real).

Hay un manual para mover una wiki en general, sin embargo, eso es demasiado complicado si todo lo que se necesita es cambiar el directorio de instalación (y permanecer en el mismo servidor, la misma base de datos y el mismo nombre de ordenador).

Esto es lo que tienes 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 en LocalSettings.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.

Nota para los usuarios con alojamiento compartido: muchos planes de alojamiento compartido ofrecen un administrador de aplicaciones para instalar, actualizar y realizar copias de seguridad automáticamente de aplicaciones como 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.

Trucos

Véase también

  • $wgActionPaths - configuration setting that you can use to define 'pretty' URLs for other actions, like edit or history

Enlaces externos

  • MediaWiki Short URL Builder Tool - A tool that can automatically generate a short url configuration more reliably than the configurations in these manual pages.

Referencias

  1. Bugzilla mod_rewrite for ampersand bug, partially resolved for some users, but only after 13 years