2014-03-05 73 views
0

我試圖從Nginx的重寫問題外部鏈接

http://domain.com/member/blog_post_view.php?postId=1 

永久重定向設置爲

http://blog.domain.com/friendly-url-here 

源URL包含一個?和一個=我認爲可能是原因,但我不確定。

我已經試過各種nginx的suggestiosn,包括下面的一個,但似乎無法得到重定向工作,希望有人能指出我在正確的方向。

location /blog_post_view.php?postId=1 { 
    rewrite "/blog_post_view.php\?postId\=1" http://blog.domain.com/friendly-url-here permanent; 
} 

回答

0

從問號開始請求線的部分稱爲query string,而location指令僅URI的路徑部分相匹配。

您應該使用$ arg_ *變量,而不是:

location =/blog_post_view.php { 
    if ($arg_postId = 1) { 
     return 301 http://blog.domain.com/friendly-url-here; 
    } 
} 

參考:

+0

嗯,我明白了什麼喲你說關於查詢字符串。我認爲會是一個問題。 不幸的是,這段代碼並不適用於我 – MartinC

+0

看來我需要在位置中包含完整路徑(域名後)。 一旦我用/member/blog_post_view.php所有工作正如我所料。 對於一個新手來說只是一個小問題 - 我錯誤地推測Nginx會識別並匹配部分URL,但似乎不是。 感謝VBart對他的精彩幫助。 – MartinC