I now have a need for SEO optimization. The code uses the Yii framework. Now I need to change some of the original long links into short links. I have two ideas for this. One is to make a 301 jump in PHP. One is to do 301 in the nginx configuration file. The problem is: I can’t match it in the nginx configuration file location? For example, the original link is xxx.bbb.ccc/index.php?r=pc/index/index, and now Using xxx.bbb.ccc/index, how can I match this?
黄舟2017-07-01 09:14:11
According to you, shouldn’t it be accessing xxx.bbb.ccc/index
-> xxx.bbb.ccc/index.php?r=pc/index/index
?
In this case, there is no need to match ?
.
Just write rewrite
the rules
rewrite ^/index$ /index.php?r=pc/index/index last;
If it is reverse, use if
to judge it
For example:
server {
server_name test.dev;
location / {
if ($request_uri ~ '/index.php\?r=pc/index/index') {
return 301 http://test.dev/index;
}
}
}
Test results:
> curl -I 'http://test.dev/index.php?r=pc/index/index'
HTTP/1.1 301 Moved Permanently
Server: nginx/1.10.3
Date: Fri, 30 Jun 2017 09:04:12 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: http://test.dev/index