Manual:Short URL/Apache/it

From mediawiki.org
This page is a translated version of the page Manual:Short URL/Apache and the translation is 67% complete.
Outdated translations are marked like this.
Indirizzi brevi per Wikipedia.

Queste istruzioni sono d'aiuto per l'impostazione di indirizzi brevi su Apache. Il server web LiteSpeed è compatibile con Apache e può essere configurato relativamente allo stesso modo. Per informazioni su cosa sono gli indirizzi brevi (Short URLs), o per istruzioni sulla configurazione per altri server, vedi Manual:Short URL . Se non sai quale server stai usando, ad es. perché utilizzi qualche tipo di servizio hosting, è probabile che tu stia usando Apache.

Setup

Prima di iniziare, devi decidere il nome del percorso dei tuoi indirizzi brevi.

In questo manuale raccomandiamo, e diamo per sottinteso, ciò che segue. Ricorda di usare sempre i tuoi specifici percorsi se sono diversi.

  • La directory MediaWiki si trova a: /w
  • Il formato di indirizzo breve desiderato è: /wiki/Page_title

Configurazione del server

Trova il file giusto

Il modo raccomandato di impostare indirizzi brevi in Apache è mediante modifica dei file di configurazione di Apache. Ciò richiede che tu abbia accesso alla configurazione del server. Se ti trovi in un hosting condiviso, assai probabilmente non avrai questo accesso e dovrai invece usare un file .htaccess. Usare i file .htaccess è meno efficiente e non ti offre lo stesso controllo in caso di setup complessi con domini multipli; ma i file .htaccess sono comunque abbastanza potenti da consentirti di impostare la maggior parte delle configurazioni di indirizzi brevi. Gli utenti di LiteSpeed dovrebbero usare il metodo .htaccess.

Usa le istruzioni che trovi in una delle due seguenti sezioni, a seconda del fatto che tu abbia un accesso root o che debba usare invece i file .htaccess.

Trova i file di configurazione di Apache (accesso root)

Il file di configurazione da modificare per le configurazioni root potrebbe essere in uno qualsiasi fra numerosi possibili posti.

Il file corretto da modificare è quello in /etc/apache2/sites-available/ laddove la configurazione del tuo wiki sia già stata impostata. La maggior parte delle distribuzioni Linux integrano Apache con un set di directory sites-available/ e sites-enabled/ di impostazioni.

Se non ne hai impostata una, e se stai usando la preimpostata /var/www per il setup del tuo wiki, allora puoi modificare /etc/apache2/sites-available/default.

Non dimenticare di abilitare in /etc/apache2/apache2.conf il superamento (override) con AllowOverride All. È disabilitato di default in Ubuntu 12.04 e Ubuntu 12.10.

Se la tua distribuzione non contiene queste directory, dovresti modificare il file di configurazione di Apache direttamente. Questo file dovrebbe trovarsi in /etc/apache2/apache2.conf. Nota che una volta lo si chiamava httpd.conf, se per caso tu hai un httpd.conf e nessun apache2.conf, allora il file che devi editare è httpd.conf.

Se il tuo file config di Apache non è in nessuno di questi luoghi, consulta la documentazione di qualsiasi cosa tu abbia usato per installare Apache, e trova dove si trova il file di configurazione.

Se sei in un hosting condiviso senza accesso ai file di configurazione di Apache, allora dovrai usare un file .htaccess.

In un file di configurazione Apache probabilmente hai un blocco VirtualHost che contiene il tuo wiki. Se ce n'è uno, è lì che le tue direttive (rewrite rules) devono andare. RewriteRule config does not inherit so don't put these config options in the global config if you are using a VirtualHost.

Dopo aver sistemato come sopra indicato il file config dentro Apache, dovrai riavviare Apache per applicare le modifiche.

  • Se stai usando cPanel o Plesk, dovrebbe esserci una funzione per il riavvio del server.
  • Da riga di comando, il comando in genere è qualsoa tipo apache2ctl graceful, apachectl graceful, /etc/init.d/apache2 restart o, come nelle più recenti versioni di Fedora, systemctl reload httpd.service. Questi comandi vanno impartiti come root, in genere meglio se premettendo sudo ....

Dove vanno messi i file .htaccess

On Apache the AllowOverride controls whether .htaccess files are allowed to control server configuration. If these rewrite rules do nothing at all you may have to modify the AllowOverride setting in the Apache config to include FileInfo. It also requires Options FollowSymLinks for the directory.

If you're using a .htaccess file you'll need to edit or create the file. Find the path that contains both your script path and your virtual path. Usually this means the top directory of your site, but let's look at a few examples:

wgScript Esempio wgArticlePath Esempio .htaccess location
/w/index.php https://www.mediawiki.org/w/index.php?... /wiki/Page_title https://www.mediawiki.org/wiki/Manual:Short_URL /.htaccess
/w/index.php https://www.mediawiki.org/w/index.php?... /Page_title https://www.mediawiki.org/Manual:Short_URL /.htaccess
/mediawiki/index.php https://www.mediawiki.org/mediawiki/index.php?... /view/Article https://www.mediawiki.org/view/Manual:Short_URL /.htaccess
/mysite/mw/index.php https://www.mediawiki.org/mysite/mw/index.php?... /mysite/view/Page_title https://www.mediawiki.org/mysite/view/Manual:Short_URL /mysite/.htaccess

Note that if you want to make a redirect from the main domain to your wiki's Main Page (e.g. http://example.org/ → http://example.org/wiki/Main_Page). Then you always have to set up the .htaccess file in the top level, even if the other directories are nested deeper.

Impostare le regole di riscrittura (rewrite rules)

Sarà più agevole comprendere il resto di questa sezione non appena data un'occhiata alla sintassi di Apache, ma questa sinossi non è un surrogato o un succedaneo della documentazione ufficiale di Apache:

RewriteCond TestString CondPattern
RewriteRule Pattern Substitution [flags]

La direttiva RewriteCond definisce una condizione che deve essere vera prima che una regola di riscrittura (RewriteRule) che la segue possa essere applicata. Una o più direttive RewriteCond possono precedere una direttiva RewriteRule, e tutte le direttive RewriteCond che precedono una RewriteRule devono essere vere prima che quella regola possa essere applicata a un URI. Nell'esempio che segue, TestString prende la forma di un riferimento a variabili server, ad es. %{ NAME_OF_VARIABLE }. Although many CondPatterns exist, the examples that follow use -f (true when TestString is a regular file) and -d (true when TestString is a directory), and they are preceded by a negation symbol, !.

The RewriteRule directive may be invoked in both the httpd.conf file and in any .htaccess file, but when the rewrite rule appears in .htaccess files, the implicit per-directory context affects the rule's Pattern because rules are relative to the current directory. In .htaccess files, Patterns are not relative to the complete, original URI. For .htaccess files, Patterns should never start with a forward slash, /, because the URI sub-string will never begin with a /. The examples that follow use the L flag whose meaning is Stop the rewriting process immediately, and don't apply any more rules.



The mod_rewrite module must be enabled in Apache or LiteSpeed servers for the examples that follow.
If you are using VirtualHosts, be sure that settings are placed inside the VirtualHost declaration

The first rule you'll need inside of your config is one to enable the rewrite engine:

RewriteEngine On

Now we need a rule to make your article path a virtual path pointing to index.php. Be sure to replace /wiki and /w/index.php with the paths you chose in the beginning (if different).

RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]
If you decide to customize this, be sure to never include ?title=$1 or something like it in the rewrite. Including a query will cause MediaWiki's built in handling to be overridden and will create bugs on your wiki due to the fact that Apache's query rewrites are broken.[1] The goal here is to alias paths to /index.php and then let MediaWiki itself take care of parsing and routing the url, based on the configuration in LocalSettings.php.

If you are using a root url instead of a normal short url you will need to use the following instead (to ensure that existing files and directories are not seen as article, e.g. "/index.php" "/images" etc.):

RewriteCond %{REQUEST_URI} !^/w/rest\.php
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/w/index.php [L]
If you are using a script path and article path that match such as /mywiki/index.php and /mywiki/Article you will also need to use the same two RewriteCond lines on your RewriteRule. However please note that there is no real valid reason to configure your wiki this way. If your article path is already a subdirectory you should just move your wiki's script path to another directory. Such as /w/index.php and /mywiki/Article or /my/index.php and /mywiki/Article.

Sometimes, the above example doesn't work. The following (you can't set this in a .htaccess, you need root access for this!) might work instead:

Alias /wiki /path/to/your/webroot/w/index.php

Optionally, you can include a rule to show the Main Page on the path itself, to simplify navigation when people visit urls without a page title specified:

# Redirect / alla Pagina Principale
RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]

Il risultato finale dovrebbe apparire più o meno così:

## https://www.mediawiki.org/wiki/Manual:Short_URL/Apache

# Abilita il motore di riscrittura (rewrite engine)
RewriteEngine On

# Indirizzi brevi (Short URL) per pagine wiki
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]

# Redirect / alla Pagina Principale
RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]

or, if you used the way with the "Alias" statement:

## https://www.mediawiki.org/wiki/Manual:Short_URL/Apache

Alias /wiki /path/to/your/webroot/w/index.php
# Abilita il motore di riscrittura (rewrite engine)
RewriteEngine On

# Redirect / alla Pagina Principale
RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]
Assicurati che sia preservato l'ordine delle regole così come indicato nell'esempio, ad es. "Short url for wiki pages" deve essere elaborato prima di "Redirect / to Main Page".
Il ^/? nel config è importante perché diverse configurazioni di Apache usano diverse regexp. Alcune richiedono che tu usi ^wiki/ e altre richiedono che usi ^/wiki/. Il ? in /? permette a questa regola di funzionare in entrambi i contesti.
The %{DOCUMENT_ROOT} in the config ensures that Apache has the correct non-ambiguous path. However it does not work on some badly configured free hosts. If you have 404 or 403 issues with your RewriteRules, remove the %{DOCUMENT_ROOT} parts and try again.
If your SCRIPT_PATH leads to some other physical location (known as "symlink" in Unix, "shortcut" on Windows, "alias" in Mac OS X), you may need to allow Apache to follow those. You can do so by adding this line above the RewriteEngine:
Options +FollowSymLinks
If the path to your script directory is aliased by the webserver via an Alias directive, as it is in Debian among others, the RewriteRule will work as long as you add the PT flag (ie: change [L] to [PT,L]) to Pass Through the request to the next handler - mod_alias, which will correctly redirect the request, as per Stack Overflow

LocalSettings.php

Dobbiamo creare le seguenti configurazioni in LocalSettings.php:

## https://www.mediawiki.org/wiki/Manual:Short_URL
$wgScriptPath = "/w";        // questo dovrebbe già essere stato configurato in questo modo
$wgArticlePath = "/wiki/$1";

Se ti succede di ottenere una pagina di "Internal error" (errore interno) che dice "Redirect loop detected!" (individuata ripetizione infinita fra i redirect) dopo il termine della configurazione, potrebbe darsi che stai usando qualcosa di diverso dal mod_php. In tal caso, devi abilitare esplicitamente gli indirizzi brevi usando la seguente riga nel tuo LocalSettings.php:

$wgUsePathInfo = true;

Se ancora ti viene restituito un "internal error" verifica i file di registro (log) del tuo server. Forse devi abilitare il modulo mod_rewrite.

Istruzioni semplificate

Ciò che segue è una sintesi di cosa fare se non stai facendo nulla di diverso da quanto MediaWiki raccomanda. Se vuoi fare qualcosa di diverso, dovrai leggere tutti i dettagli sopra.

  • https://example.com/wiki/Main_Page (url location (posizione dell'indirizzo))
  • /home/me/public_html/mediawiki/w/index.html (index.html location)
  • /home/me/public_html/mediawiki/.htaccess (.htaccess location)

Nota che il file .htaccess NON si trova nella directory "w", ma in quella sopra di questa.

Codice Sorgente di .htaccess

RewriteEngine On

# principale regola di riscrittura (rewrite rule)
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]

# Redirect / alla Pagina Principale
RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]

Codice Sorgente di LocalSettings.php

$wgScriptPath = "/w";
$wgArticlePath = "/wiki/$1";

Online Wizard

It is possible that this wizard will help people generate the short URLs they need. (NOTE: This needs to be tested, or the section removed.)

An automated wizard (requires MediaWiki 1.17 or later) might help:

If you just want your wiki configured quickly or you find the guide confusing then you may want to try that tool first. If you do this, please note that you will need to edit or create a .htaccess file. If you create it anew, please read on to further in this article about where to place the .htaccess file, and please note that this file will likely be in a different folder than the other file that will need to be edited (LocalSettings.php), which is in the installation folder (/w if you have followed the MediaWiki recommendations). Please also note that using this wizard will not work on firewalled or private wikis. In this case, you can still try it out by making your wiki temporarily public by setting $wgGroupPermissions['*']['read'] to true. Remember to change it back to false once you are done.

Vedi anche

Note