Nginx matching URL with question mark
为情所困
为情所困 2017-07-01 09:12:11
0
1
1041

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?

为情所困
为情所困

reply all (1)
黄舟

According to you, shouldn’t it be accessingxxx.bbb.ccc/index->xxx.bbb.ccc/index.php?r=pc/index/index?

In this case, there is no need to match?.

Just writerewritethe rules

rewrite ^/index$ /index.php?r=pc/index/index last;

If it is reverse, useifto 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
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!