2016-04-26 54 views
0

我會盡量簡短。我有以下的nginx重寫網址:nginx重寫&參數全url和文件擴展名

rewrite ^/(.*)?$ /index.php?completeURL=$1 last; 

我要像一個網址:

http://mywebsite.com/http://www.otherwebsite.com/dir1/dirx/article.php&id=2&category=1 

要求:

http://mywebsite.com/index.php?completeURL=http://www.otherwebsite.com/dir1/dirx/article.php&id=2&category=1 

目前nginx的規則有問題。 示例:如果參數包含.php擴展名,他會在我的服務器上查找該文件。

例子:http://mywebsite.com/dir1/dirx/article.php

如何解決在您看來這個問題呢?


UPDATE: 這裏nginx的配置(和重寫)文件:

回答

0

釷最簡單的解決方案(假定服務器除了服務index.php之外不做其他任何事情)將刪除通常的location ~ \.php$塊,並在與fastcgi_pass相同的塊中執行rewrite ... break;。有許多的實現這一點,包括方式:

location/{ 
    rewrite ^/(.*)?$ /index.php?completeURL=$1 break; 
    fastcgi_pass ... 
    ... 
} 

另一種策略是只有本地文件不存在進行重寫,但你需要確保.php文件過測試。例如:

location/{ 
    try_files $uri $uri/ @rewrite; 
} 
location ~ \.php$ { 
    try_files $uri @rewrite; 
    fastcgi_pass ... 
    ... 
} 
location @rewrite { 
    rewrite ^/(.*)?$ /index.php?completeURL=$1 last; 
}   
+0

我想你的第二個解決方案,但我得到這個錯誤: '2016年4月26日22時21分05秒[錯誤] 10591#0:* 1846重寫或內部重定向循環,同時重定向到命名位置「@rewrites」,客戶端:xx.xx.xx.xx,服務器:website.com,請求:「GET /http://www.website.com/dfgdfgghgh.cfm HTTP/2.0」,主機:「 website.com「' – Ivan

+0

如果/index.php不存在,它將循環。 'root'是否正確定義? –

+0

嗨@Richard Smit。我更新了我的帖子。我已經包含了完整的nginx配置文件。試着給我們看看。 – Ivan