在Nginx中,可以通过配置重定向指令来实现路径重定向。以下是两种常用的重定向方法:
server {
listen 80;
server_name example.com;
location /old-path {
return 301 /new-path;
}
location /new-path {
# 处理新路径的内容
}
location / {
# 其他路径的处理
}
}
server {
listen 80;
server_name example.com;
rewrite ^/old-path$ /new-path permanent;
location /new-path {
# 处理新路径的内容
}
location / {
# 其他路径的处理
}
}
上述示例中,当用户访问/example.com/old-path时,会被重定向到/example.com/new-path路径上。可以根据实际需求选择使用return或者rewrite指令来实现路径重定向。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: nginx设置301跳转后有时候居然无法跳转