2012-07-27 104 views
2

我對nginx來說有些新鮮,並且在重寫時遇到困難。我想獲得:URL參數和重寫

/C/545_453453_4534

訪問c.php傳遞545_453453_4534作爲PARAMS

這裏是我當前的conf:

location/{ 
     try_files $uri $uri/ @extensionless-php; 
     index index.html index.htm index.php; 
    } 

    location ~ \.php$ { 
      try_files $uri =404; 
      fastcgi_pass 127.0.0.1:8000; 
      include /etc/nginx/fastcgi_params; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    } 

    location @extensionless-php { 
      rewrite ^(.*)$ $1.php last; 
    } 

謝謝!

回答

0

在你的NGINX服務器塊,你需要添加:

rewrite ^/c/([^/]*)$ /c.php?param=$1 last; 

我傾向於做的是生成我重新寫Apache的風格,那麼用它轉換爲NGINX格式:

http://www.anilcetin.com