首页 > 解决方案 > 在 NGINX 中执行 301 重定向时跳过参数

问题描述

第一次在这里发帖。因此,我使用此代码将特定页面从一个域重定向到另一个域。

if ( $request_filename ~ / ) { rewrite ^ https://example.net permanent; }

是否可以选择跳过该代码中的任何内容,包括“?d =”?我不希望 ?d= 之后的任何页面包含在重定向中。

标签: nginxhttp-status-code-301

解决方案


如果重写的 URL 以 , 结尾?rewrite则不会复制任何原始参数。

例如:

rewrite ^ https://example.net/? permanent;

有关详细信息,请参阅此文档


或者,使用更简单的return表达式:

return 301 https://example.net/;

推荐阅读