You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NGINX技术问题:如何移除URL参数并返回原内容以优化SEO?

实现带参数URL的SEO友好重定向

当然可以实现你的需求,以下是两种Nginx配置方案,既能将带参数的/url_org?id=20重定向到SEO友好的/url_org/dir,同时保证新URL返回原内容:

方案1:使用rewrite指令

可以精准匹配带参数或不带参数的/url_org请求,执行永久重定向:

# 匹配不带参数的/url_org
rewrite ^/url_org$ /url_org/dir permanent;
# 匹配带任意参数的/url_org请求
rewrite ^/url_org\?.*$ /url_org/dir permanent;

或者用一条更简洁的规则覆盖所有情况:

rewrite ^/url_org(/?.*)$ /url_org/dir permanent;

方案2:使用return指令结合location块

通过location匹配目标请求,直接返回301重定向响应:

# 匹配不带参数的/url_org
location = /url_org {
    return 301 /url_org/dir;
}
# 匹配带参数的/url_org请求
location ~ ^/url_org\? {
    return 301 /url_org/dir;
}

也可以用宽泛匹配简化配置(注意避免影响其他以/url_org开头的合法路径):

location ^~ /url_org {
    return 301 /url_org/dir;
}

关键注意事项

  • 两种方案都使用了301永久重定向(permanent对应rewrite,return直接指定301),这是SEO友好的核心,能让搜索引擎更新索引,将流量导向新的干净URL。
  • 必须确保/url_org/dir对应的location配置正确,能返回原/url_org?id=20的内容,避免出现404错误。

内容的提问来源于stack exchange,提问作者mazman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 05:06:02