Manual:Short URL

Jump to navigation Jump to search
This page is a translated version of the page Manual:Short URL and the translation is 21% complete.
This article is about URL structure. For creating short URLs for articles, see Extensão:ShortUrl . For creating a URL shortening service, see Extension:UrlShortener .

Short URLs ou URL Rewrites escondem a extensão php dos arquivos no endereço da página. Por favor, dedique alguns minutos criando uma estrutura estável de URL para seu site antes de começar, para evitar problemas futuros.



O caminho de instalação padrão do MediaWiki geralmente parece com isso:

/var/www/localhost/htdocs/mediawiki/w (instalado como usuário root)
/home/johndoe/public_html/mediawiki/w (instalado em um provedor de hospedagem compartilhada)

Os endereços da página padrão do MediaWiki parecem com estes exemplos: (versões mais recentes do MediaWiki, sem suporte CGI) (versões mais recentes do MediaWiki, com suporte CGI)

Usando os métodos abordados nesta página, podemos configurar para algo assim: Esta é a configuração mais comum, o mesmo que a Wikipédia, embora não seja a padrão porque requer algumas modificações no lado servidor.

Vantagens e desvantagens

  • Vantagem: Short URLs escondem alguns detalhes técnicos dos usuários finais, o que pode ser desejável para os donos do site. Entre outras coisas, isto significa que eles podem manter-se estáveis quando o software por baixo deles mudar. (Veja acima a diferença entre a estrutura de URL padrão do MediaWiki com CGI habilitado vc não-habiltado) Também são mais fáceis de ler, lembrar e manipular pelos visitantes. Além disso, short URLs tem a vantagem sobre as URLs padrão de pt:Otimização para motores de busca, já que URLs contendo ? podem ser tratadas de modo menos favoráveis por engines de busca ao calcular a colocação da página.
  • Desvantagem: Precisa ser configurado, então, dependendo do ambiente de servidor que você está usando, pode ser difícil de recriar. Entretanto, como todo servidor web amplamente usado é capaz de ser configurado para short URLs, a maioria dos serviços de hospedagem pagos devem suportar este recurso. Qualquer hospedagem que não ofereça este recurso não vale seu dinheiro.


Nossos guias oficiais para configuração de short URL para diferentes servidores web. Escolha a configuração do seu servidor web na lista. Se voê não sabe que software servidor está usando, então provavelmente é o Apache.

Outros mini-guias de como-fazer

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 -

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 -

Atenção Atenção: This is probably only appropriate if your domain is only being used for MediaWiki, but even then it is typically not recommended, as this setup can leave some titles unusable. See Manual:Wiki in site root directory and Cool URIs don't change.

How to create URLs:

URL like -

Atenção Atenção: This is probably only appropriate if your domain is only being used for MediaWiki, but even then it is typically not recommended, as this setup can leave some titles unusable. See Manual:Wiki in site root directory and Cool URIs don't change.

How to create URLs:


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]


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.

No Skins

With Ubuntu 8.10 and MediaWiki 1.11.2 (and maybe later versions) if you use the MediaWiki sanctioned directions your skins may fail to load. To fix this, create a symbolic link in /var/www pointing to /var/lib/mediawiki with the value of $wgScriptPath in LocalSettings.php. If, for example, $wgScriptPath is set to "/w" then you need to run the command "sudo ln -s /var/lib/mediawiki /var/www/w".

Alternatively, try setting $wgLoadScript to the original file. If your source url is /wiki with the short url /w, set it to /wiki/load.php.

Purging cache

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

Go to 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)

Redirect visitor of your domain to your wiki

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 Apache guide recommends using this to point your site root to your 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. Simply rewrite the root path to MediaWiki and it will take care of the 301 redirect to the main page itself.

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

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).

Here is what you have to do:

  • Backup LocalSettings.php and any other config files you may have created (such as your .htaccess).
  • Rename the installation directory of MediaWiki on your server from /wiki to /w.
  • Set $wgScriptPath in LocalSettings.php to "/w" and remove (or comment out) any definition of $wgArticlePath (this variable will be changed again when setting up Short URLs, further on)
  • At this point your wiki should be working normally at
  • Perform a few tests on your wiki to make sure nothing is broken.

Edit a page, visit a few different pages, etc. If anything seems abnormal, revert the changes by restoring your backup of LocalSettings.php and other relevant files you might have changed during configuration of short URLs and rename your folder back to /wiki.

Note for shared hosting users: Many shared hosting plans offer an application manager to automatically Install, Update and Backup applications such as MediaWiki. 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.


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

External links

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


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