简体   繁体   English

使用Nginx进行301重定向的正确方法

[英]Proper way to 301 redirect using Nginx

I'm using Nginx as a webserver. 我正在使用Nginx作为网络服务器。 I need to 301 redirect url in following pattern 我需要按照以下模式301重定向URL

adomain.com/detail.php?name=eC-F_VZ2T1c

into 进入

adomain.com/watch?v=eC-F_VZ2T1c

Tried this snippet 尝试过此片段

location /detail.php {
    if ($arg_name) {
        return 301 http://adomain.com/watch?v=$arg_name;
    }
}

No success! 没有成功!

What am I doing wrong? 我究竟做错了什么?

You might have better luck with rewrite - try replacing your return line with the following: rewrite可能会带来更好的运气-尝试用以下命令替换回车行:

rewrite ^ http://adomain.com/watch?v=$arg_name permanent;

The permanent flag indicates a permanent 301 redirect. permanent标志指示永久301重定向。

As per documentation found at: 根据位于以下位置的文档:

http://nginx.org/en/docs/http/ngx_http_rewrite_module.html http://nginx.org/en/docs/http/ngx_http_rewrite_module.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM