2017-04-06 79 views
1

我想用参数301将一个特定的URL重定向到另一个具有新参数的特定URL。NGINX用参数重写一个带有参数的URL到另一个带有新参数的URL

https://www.example.com/index.php?id=329

https://www.example.com/index.php?eID=dd_googlesitemap

我试过的东西,但我觉得有几个错误。

location = /index.php?id=329 { 
    rewrite^https://www.example.com/index.php?eID=dd_googlesitemap permanent; 
} 

OR

location = /index.php { 
    if ($arg_id = "329") { 
     rewrite^https://www.example.com/index.php?eID=dd_googlesitemap permanent; 
    } 
} 

OR

location = /index.php { 
    if ($args ~ "id=329") { 
     rewrite^https://www.example.com/index.php?eID=dd_googlesitemap permanent; 
    } 
} 

谁能帮助?

谢谢!

回答

0

/index.php URI由location ~ \.php$块处理,并包含将文件名发送到PHP以执行的所有必需语句。如果您要为/index.php创建新的location,则还需要复制这些语句。

例如:

location = /index.php { 
    if ($arg_id = "329") { 
     return 301 /index.php?eID=dd_googlesitemap; 
    } 
    ... php statements ... 
} 
location ~ \.php$ { 
    ... php statements ... 
} 

备选地,检查它进入location块之前的URI

例如:

server { 
    ... 
    if ($request_uri = "/index.php?id=329") { 
     return 301 /index.php?eID=dd_googlesitemap; 
    } 
    ... 
} 

参见this document更多。