在所有'在nginxredirect'的问题中,我找不到如何使用regexpsredirect(使用返回301和更好的没有ifs)。
我有一个链接到我的网站,我想删除参数结束:
domain.com/article/some-sluggish-link/?report=1 #number at end
正则expression式来find这个:
\?report=\d*$
为此,我想301redirect到:
domain.com/article/some-sluggish-link/
我nginx.conf我有3个redirect:
server { listen 80; server_name subdomain.example.com.; #just one subdomain } server { listen 80; server_name *.example.com; return 301 http://example.com$request_uri; } server { listen 80; server_name example.com; }
它的工作; 它将所有www。,ww。,aaa。,301以及除1个以外的每个子域redirect到main domain.com
我会很感激任何帮助干杯!
编辑25/03/2015
我的conf文件中已经有“location /”了:
location / { uwsgi_pass unix://opt/run/ps2.sock; include uwsgi_params; }
redirect到一些Django的应用程序。 应用“if”条款后,它给我无限循环!
我的问题基本上是与search引擎优化,这意味着谷歌索引一些特定的页面(那些'?报告='参数)是没有这个尾随参数的url副本。
我希望googlebot停止索引使用robots.txt,但问题是你不能在这个文件中使用正则expression式。 此外,我不能说哪个url准确地nedd被redirect或从索引停止导致它随机发生的…
我没有尝试过这个,但它应该工作。 将其添加到您的服务器{}块中:
location / { if ($args !~ ^$) { rewrite ^ $request_uri? permanent; } }
这个块实际上做了什么:
location /告诉nginx将这些指令应用于所有匹配根目录和子目录的请求。
if ($args !~ ^$)检查URI是否包含任何具有正则expression式的查询参数。
rewrite ^ $request_uri? permanent; 使redirect到所需的URI没有任何查询参数。 这个? $ request_uri的结尾告诉nginx从redirectURL中去掉查询参数。