2013-08-24 13 views
12

Sto usando Nginx per un semplice sito web demo, e ho appena configurare il Nginx in questo modo:Come rendere caso URL insensitive con Nginx

server { 
    listen   80; 
    server_name  www.abc.com; 

    location/{ 
     index   index.html; 
     root   /home/www.abc.com/; 
    } 
} 

Nella mia cartella www.abc.com, ho sotto-cartella denominata Sub, e all'interno ha il file index.html. Quindi quando provo a visitare www.abc.com/Sub/index.html, allora funziona bene. Se visito lo www.abc.com/sub/index.html, restituisce 404.

Come configurare Nginx su maiuscole/minuscole nell'URL?

risposta

17
server { 
    # Default, you don't need this! 
    #listen   80; 

    server_name  www.abc.com; 

    # Index and root are global configurations for the whole server. 
    index   index.html; 
    root   /home/www.abc.com/; 

    location/{ 
     location ~* ^/sub/ { 
      # The tilde and asterisks ensure that this location will 
      # be matched case insensitive. nginx does not support 
      # setting absolutely everything to be case insensitive. 
      # The reason is easy, it's costly in terms of performance. 
     } 
    } 
} 
+0

wow, grazie mille. –

+0

La soluzione di cui sopra non funziona per me..Per favore mi aiuti. ~ * Funziona solo se condizione – Catmandu

+3

Penso che questo corrisponderà a tutti gli URL * contenenti */sub/(ad esempio, corrisponderebbe anche a "example.com/yellow /sub/"). Dovrebbe essere 'posizione ~ * ^/sub /' (con il segno di omissione). –

Problemi correlati