2016-01-21 16 views
1

這裏是我重寫代碼:如何讓nginx的rewrite a.php只會,b.php,c.php到的index.php

location/{     
     if (!-e $request_filename){ 
      rewrite "(*UTF8)^/(.*)$"/last; 
     } 
    } 

    location ~ \.php$ {    
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include  fastcgi_params; 
     fastcgi_param PHP_VALUE "open_basedir=$document_root:/tmp/:/proc/"; 
    } 

我想重寫a.php只會,b.php,c.php到/index.php.but它不起作用!但是當我鍵入一個.c,上面的代碼可以工作,我犯了一些錯誤?

+0

嘗試'重寫^(。*)$ /index.php最後;'' –

回答

0

您目前的問題是任何具有.php的URI都由PHP位置塊處理,因此會繞過您的重寫規則。在您的/位置和您的PHP位置使用try_files。例如:

location/{ 
    try_files $uri $uri/ /index.php; 
} 

location ~ \.php$ { 
    try_files $uri /index.php; 

    fastcgi_pass 127.0.0.1:9000; 
    include  fastcgi_params; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    fastcgi_param PHP_VALUE "open_basedir=$document_root:/tmp/:/proc/"; 
} 

請參閱this document瞭解更多信息。

相關問題