Rewrite Rules
Rewrite rules allow you to modify and redirect URLs in your application. This feature is useful for URL redirection, path rewriting, and maintaining backward compatibility.
Configuration Structure
rewrite:
- name: test
path: "/testredirect"
target: https://ax.target.example.com
code: 301
enabled: true
Configuration Options
Name
- Type: String
- Required: Yes
- Description: Unique identifier for the rewrite rule
- Example:
name: "test"
Path
- Type: String
- Required: Yes
- Description: The URL path pattern to match
- Example:
path: "/testredirect"
Target
- Type: String
- Required: Yes
- Description: The destination URL for the rewrite/redirect
- Example:
target: "https://ax.target.example.com"
Code
- Type: Integer
- Default:
301
- Description: HTTP status code for the redirect
301
: Permanent redirect302
: Temporary redirect307
: Temporary redirect (preserves method)308
: Permanent redirect (preserves method)- Example:
code: 301
Enabled
- Type: Boolean
- Default:
true
- Description: Whether the rule is active
- Example:
enabled: true
Best Practices
- Use descriptive names for your rules
- Always test redirects in a staging environment first
- Use appropriate status codes:
301
for permanent redirects302
for temporary redirects- Keep rules organized and documented
Example Configurations
Basic Redirect
rewrite:
- name: "old-to-new"
path: "/old-path"
target: "https://example.com/new-path"
code: 301
enabled: true
Multiple Redirects
rewrite:
- name: "blog-redirect"
path: "/blog"
target: "https://blog.example.com"
code: 301
enabled: true
- name: "api-redirect"
path: "/api"
target: "https://api.example.com"
code: 302
enabled: true