locationHref
For scenarios where server-side redirection (302/301) is unavailable, client-side redirection can be achieved by returning the JavaScript code window.location.href = targetUrl in the HTML page. Especially suitable for:
- App pages loaded from local HTML files
- Single-Page Applications (SPAs)
- Hybrid Apps developed with special frameworks
Rule Syntax
txt
pattern locationHref://targetUrl [filters...]| Parameters | Description | Detailed Documentation |
|---|---|---|
| pattern | An expression to match the request URL | Match Pattern Documentation |
| targetUrl | The redirected URL, which can be a relative path | |
| filters | Optional filters, supporting matching: • Request URL/Method/Headers/Content • Response Status Code/Headers | Filter Documentation |
Configuration Example
Basic Configuration
txt
www.example.com/path locationHref://https://www.qq.com
www.example.com/path2 locationHref://../abc/123- Visiting
https://www.example.com/path/toredirects tohttps://www.qq.com(no automatic path concatenation) - Visiting
https://www.example.com/path2/toredirects tohttps://www.example.com/abc/123
Implementing Path Concatenation
txt
# Wildcard
^www.example.com/path/*** locationHref://`https://www.example.com/$1`- Visiting
https://www.example.com/path/to?queryredirects tohttps://www.example.com/to?query
location.replace
To implement a page redirect without history history using location.replace(targetUrl), use the following configuration format:
txt
www.example.com/path locationHref://replace:https://www.qq.comRedirects to the target URL. The current page will not be saved in the browser history, and users cannot return to the original page using the "Back" button.
Associated Protocols
- Return status code directly (request is not sent to the server): statusCode
- Replace the status code returned by the server: replaceStatus
- Client-side page redirect: locationHref