2010-03-29 230 views
3
rewrite ^/index\.asp /index.php last; 
rewrite ^/index\.asp\?boardid=([0-9]+)$ /forum-$1-1.html last; 
rewrite ^/index\.asp\?boardid=([0-9]+)(.*)$ /forum-$1-1.html last; 
rewrite ^/index_([0-9]+)(.*)$ /forum-$1-1.html last; 
rewrite ^/dispbbs\.asp\?boardID=([0-9]+)&ID=([0-9]+)$ /thread-$2-1-1.html last; 

我已經嘗試了上面的重寫規則,並得到一個死的結果,不工作。 我參考了很多文章和文章,並沒有幫助。nginx重寫規則不起作用?

有什麼錯誤嗎?

V/R, 加文


感謝您的答覆。 :)

我已經改變了我的nginx的配置於

rewrite ^/index\.asp$ /index.php last; 
rewrite ^/index\.asp\?boardid=([0-9]+)(.*)$ /forum-$1-1.html last; 
rewrite ^/index\.asp\?boardid=([0-9]+)$ /forum-$1-1.html last; 
rewrite ^/dispbbs\.asp\?boardID=([0-9]+)&ID=([0-9]+)$ /thread-$2-1-1.html last; 

仍然沒有工作。但我在規則中找不到任何錯誤。

回答

2

您不能在重寫規則中匹配參數,它們可能只包含路徑。原因很簡單:假設參數可能有另一個命令;假設可能有其他參數沒有考慮到(例如來自Google的關鍵字)。

所以你的規則應該以一種匹配路徑的方式重寫,然後檢查參數。像這樣:

rewrite ^/index_([0-9]+)(.*)$ /forum-$1-1.html last; 

location /index.asp { 
    if ($arg_boardid ~ "^([0-9]+)") { 
    rewrite^/forum-$1-1.html break; 
    } 
    rewrite^/index.php break; 
} 

location /dispbbs.asp { 
    rewrite^/thread-$arg_ID-1-1.html break; 
} 
+0

謝謝。但是,我在nginx.config中也有像rewrite ^/dispbbs_([0-9]+)_([0-9]+)\.html$ /thread-$2-1-1.html last;這樣的規則,它們工作得很完美。我會嘗試你的分段。 :) – WisdomFusion 2010-03-29 08:27:07

+0

rewrite ^/dispbbs_([0-9]+)_([0-9]+)\.html$ /thread-$2-1-1.html last; WisdomFusion 2010-03-29 08:56:46

+0

參數(查詢字符串)後問問字符。之前您可以匹配任何內容,因爲它是一個字符串,但不能對查詢字符串進行匹配。 – 2010-03-29 09:31:39