Skip to content
On this page

URL重定向 redirect

- search: ——
  action: redirect
  redirect: 
    #跳转参数

你要找的是在外部观察url不跳转的URL重写吗? redirect可以直接返回一个跳转,无视fetch状态,对接下来的规则也将不执行。

to

to表示重定向的替换规则。

这是一个简单的例子,用于将/path跳转为/path.html

- search: \/([^\/.]+)$ #匹配/path,跳为/path.html
  action: redirect
  redirect: 
    to: /$1.html
    status: 301

url

url表示重定向的目标url。

这是一个简单的例子,将/google跳转到https://www.google.com

- search: \/google$
  action: redirect
  redirect: 
    url: https://google.com #不替换直接跳转,默认优先级url > to
    status: 301

请注意,url优先级比to高。

status

你可以选择301/302,不过这其实没有太大用处。