【发布时间】:2021-09-16 09:54:07
【问题描述】:
我正在尝试重定向这样的路径:从 www.example.com/some-path/sg/ 到 www.example.com/some-path/
但是我需要一些方法来识别这种流量,比如一个参数,理想情况下:www.example.com/some-path/?ls=sg。这可以使用 htaccess/mod_rewrite 吗?
我试过的是:
RedirectMatch 301 /sg/(.*) /$1?ls=SG7
【问题讨论】:
-
请在您的问题中分享您尝试过的 htaccess 规则文件,谢谢。
-
我试过:RedirectMatch 301 /sg/(.*) /$1?ls=SG7 ..但这只是重定向到路由,但它确实包含参数,所以不会太远。不过,我只需要保留其余的路径。
-
sg参数是否总是固定在任何类型的 url 中传递?请确认一次,因为您正在重定向到 urlwww.example.com/some-path/,它不会在 url 中,因此 htaccess 不会知道它是否在前端隐藏了一次。请确认一次。 -
不,sg 不在所有网址中,只是一些。所以当它存在时,删除它并传递一个参数,这样我就可以在它后面做其他事情
-
好的,所以 url
www.example.com/some-path/?ls=sg你在浏览器中点击?你想把它改成www.example.com/some-path/sg/吗?请确认一次
标签: apache .htaccess redirect mod-rewrite url-rewriting