docs/docs/rules/locationHref.md
针对无法通过服务端重定向(302/301)的场景,通过在 HTML 页面中返回 JavaScript 代码 window.location.href = targetUrl 实现客户端跳转。特别适用于:
pattern locationHref://targetUrl [filters...]
| 参数 | 描述 | 详细文档 |
|---|---|---|
| pattern | 匹配请求 URL 的表达式 | 匹配模式文档 |
| targetUrl | 重定向后的 URL,可以是相对路径 | |
| filters | 可选过滤器,支持匹配: | |
| • 请求URL/方法/头部/内容 | ||
| • 响应状态码/头部 | 过滤器文档 |
www.example.com/path locationHref://https://www.qq.com
www.example.com/path2 locationHref://../abc/123
https://www.example.com/path/to 重定向到 https://www.qq.com(不自动拼接路径)https://www.example.com/path2/to 重定向到 https://www.example.com/abc/123# 通配符
^www.example.com/path/*** locationHref://`https://www.example.com/$1`
https://www.example.com/path/to?query 重定向到 https://www.example.com/to?query若需通过 location.replace(targetUrl) 实现无历史记录的页面跳转,可按以下格式配置:
www.example.com/path locationHref://replace:https://www.qq.com
跳转至目标 URL,且当前页面不会存入浏览器历史记录,用户无法通过“返回”按钮回到原页面
302 跳转:redirect