2016-03-24 109 views
1

我希望能夠訪問www.mrmerch.com/TERMS和www.mrmerch.com/terms。我目前有兩個子文件夾來完成這個任務 - 條款和條款。我知道,效率低下,不正確。nginx中不區分大小寫的URL

這是我目前的配置。我添加了最後一個位置塊,但我仍然無法找到與該位置不完全匹配的任何內容(例如「條款」)。任何幫助是極大的讚賞。謝謝!

server { 
server_name www.mrmerch.com; 
return 301 $scheme://mrmerch.com$request_uri; 
} 

server { 
listen 80 default_server; 
server_name mrmerch.com; 
server_tokens off; 

access_log /var/log/nginx/mrmerch.access_log; 
error_log /var/log/nginx/mrmerch.error_log; 

root /home/paul/www/mistermerch.com/; 
try_files $uri $uri/ /index.php$is_args$args; 

gzip on; 
gzip_comp_level 6; 
gzip_vary on; 
gzip_min_length 1000; 
gzip_proxied any; 
gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; 
gzip_buffers 16 8k; 
gzip_disable "MSIE [1-6]."; 

location = /favicon.ico { 
      log_not_found off; 
      access_log off; 
    } 

    location = /robots.txt { 
      allow all; 
      log_not_found off; 
      access_log off; 
    } 

location /artwork { 
    alias /home/mistermerch/www/; 
} 

location ~ \.php$ { 
    try_files $uri =404; 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    #fastcgi_param SCRIPT_FILENAME /home/paul/www/mistermerch.com$fastcgi_script_name; 
    include fastcgi_params; 
} 

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { 
      expires max; 
      log_not_found off; 
    } 


    location ~* ^/Terms/ { 
    } 



} 

回答

2

你可以使用一個不區分大小寫的正則表達式的位置在內部重寫URI:

location ~* ^/terms { 
    rewrite^/static/terms.html last; 
} 

在這種情況下,/terms/terms//TeRmS/tErMs/等全部重寫,這是一個位置外部正則表達式匹配。

如果你想使用目標URI這也符合正則表達式的位置,你可以用精確匹配的位置解壓:

location ~* ^/terms { 
    rewrite^/terms/index.html last; 
} 
location = /terms/index.html { 
} 

詳見this document